Migrate Laysense to unmodified LaySite 1.5.2

This commit is contained in:
2026-11-28 14:44:34 +08:00
parent e39439467d
commit b08008c9ca
134 changed files with 3485 additions and 754 deletions
+136 -17
View File
@@ -25,7 +25,6 @@
.admin-license-list span { display: block; font-family: var(--mono); font-size: .85rem; }
.admin-about-links { display: flex; flex-wrap: wrap; gap: .55rem .75rem; }
.admin-about-links a { display: inline-flex; align-items: center; flex-wrap: wrap; min-height: 2.75rem; gap: .2rem .45rem; padding: .4rem .75rem; border: 1px solid var(--line); border-radius: .5rem; background: var(--white); text-decoration: none; }
.admin-about-links span { color: var(--muted); font-size: .85rem; overflow-wrap: anywhere; }
.admin-about-links svg { inline-size: 1rem; block-size: 1rem; flex: none; }
.admin-about-links a:hover { border-color: var(--accent); }
@media (max-width: 31rem) {
@@ -41,7 +40,7 @@
.login-box p { margin-block: .6rem 1.25rem; }
.admin-form { display: grid; gap: 1rem; }
.admin-form label { display: grid; gap: .4rem; font-weight: 570; color: var(--ink); }
.admin-form :where(input:not([type=hidden], [type=checkbox], [type=radio]), select, textarea) {
.admin-form :where(input:not([type=hidden], [type=checkbox], [type=radio], [type=range]), select, textarea) {
background: white;
color: var(--ink);
width: 100%;
@@ -109,10 +108,29 @@
.studio-canvas-toolbar { margin-bottom: .55rem; }
.canvas-format-tools label { display: flex; align-items: center; gap: .3rem; font-size: .875rem; }
.canvas-format-tools input { width: 4.3rem; min-height: 2.45rem; padding: .4rem; border: 1px solid var(--line); border-radius: .35rem; }
.canvas-font-picker, .canvas-font-combo { display: inline-flex; align-items: center; gap: .3rem; }
.canvas-font-combo { gap: 0; }
.canvas-font-combo input { border-start-end-radius: 0; border-end-end-radius: 0; }
.canvas-font-combo select {
width: 3.1rem; min-height: 2.45rem; padding: 0 .15rem;
color: var(--ink); background: var(--white); border: 1px solid var(--line); border-inline-start: 0;
border-start-end-radius: .35rem; border-end-end-radius: .35rem; cursor: pointer;
}
.canvas-font-combo select:disabled { opacity: .5; cursor: default; }
.canvas-format-tools [aria-pressed=true] { background: var(--accent-light); color: var(--accent-deep); }
.canvas-spacing-fields { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .5rem; }
.canvas-spacing-fields input { padding-inline: .4rem; }
.canvas-spacing-preset { grid-column: 1 / -1; grid-template-columns: max-content minmax(0, 15rem); align-items: center; }
.canvas-spacing-fields input[type=number] { padding-inline: .4rem; }
.canvas-spacing-preset {
display: grid; grid-column: 1 / -1; gap: .45rem .75rem; align-items: center; margin-block-end: .4rem;
grid-template-columns: max-content minmax(0, 1fr) 4.5rem max-content;
}
.canvas-spacing-preset input { width: 100%; min-width: 0; min-height: 2rem; margin: 0; accent-color: var(--accent); }
.canvas-spacing-preset output { color: var(--muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.canvas-spacing-preset .button { min-height: 2.25rem; padding: .2rem .6rem; font-size: .875rem; }
@media (max-width: 32rem) {
.canvas-spacing-preset { grid-template-columns: minmax(0, 1fr) 4.5rem max-content; }
.canvas-spacing-preset label { grid-column: 1 / -1; }
}
.studio-canvas-toolbar button:disabled { opacity: .5; cursor: default; }
.preview-selector { display: flex; gap: .35rem; flex-wrap: wrap; }
.preview-selector [aria-pressed="true"] { background: var(--accent-light); color: var(--accent-deep); }
@@ -182,7 +200,9 @@
.studio-layers { border-top: 1px solid var(--line); margin-top: .85rem; padding-top: .55rem; }
.studio-layers summary { cursor: pointer; font-weight: 620; }
.studio-layers[open] > summary { margin-bottom: .55rem; }
.studio-media-sizing { position: absolute; z-index: 1; inset: auto .6rem .6rem auto; display: flex; flex-wrap: wrap; align-items: center; gap: .75rem; padding: .45rem .6rem; max-width: calc(100% - 1.2rem); background: var(--accent-light); border: 1px solid var(--line); border-radius: .45rem; }
.studio-media-sizing { align-items: center; }
.studio-canvas-toolbar .studio-media-sizing button { min-height: 2.45rem; padding: .25rem .5rem; }
.studio-media-sizing output { padding-inline: .35rem; color: var(--muted); font-size: .85rem; }
.studio-element-tools {
position: absolute; z-index: 3; display: flex; align-items: center; gap: .12rem; padding: .18rem;
border: 1px solid #c7d6f3; border-radius: .52rem; background: var(--white);
@@ -406,9 +426,10 @@
/* Studio source, media controls and layer tree */
.media-upload-fields, .media-filters { align-items: start; }
.media-upload-fields input[type=file] { padding: .4rem; min-width: 0; font-size: .9rem; }
.media-upload-fields input { block-size: 3rem; }
.media-upload-fields input[type=file] { padding: .3rem .4rem; min-width: 0; font-size: .9rem; }
.media-upload-fields input::file-selector-button {
margin-inline-end: .6rem; border: 0; border-radius: .35rem; padding: .55rem .75rem;
margin-inline-end: .6rem; border: 0; border-radius: .35rem; padding: .45rem .75rem;
color: var(--accent-deep); background: var(--accent-light); font: inherit; cursor: pointer;
}
.media-filters { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }
@@ -416,25 +437,36 @@
@media (max-width: 42rem) { .media-filters { grid-template-columns: minmax(0, 1fr); } }
.canvas-source { width: min(56rem, calc(100% - 2rem)); }
.canvas-source textarea { font: .9rem / 1.55 var(--mono); tab-size: 4; }
.canvas-source .CodeMirror {
:is(.canvas-source, .head-settings) textarea { font: .9rem / 1.55 var(--mono); tab-size: 4; }
:is(.canvas-source, .head-settings) .CodeMirror {
height: clamp(12rem, 50vh, 32rem);
margin-top: .4rem;
border: 1px solid var(--line);
border-radius: .5rem;
font: .9rem / 1.55 var(--mono);
}
.canvas-source .CodeMirror-focused { outline: 2px solid var(--accent); outline-offset: 1px; }
:is(.canvas-source, .head-settings) .CodeMirror-focused { outline: 2px solid var(--accent); outline-offset: 1px; }
.head-settings-fields { display: grid; gap: .65rem; margin-block-start: .6rem; }
.head-settings .CodeMirror { height: clamp(13rem, 38vh, 22rem); margin: 0; }
.mcp-token { font-family: var(--mono); }
.favicon-editor-row { display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; }
.favicon-preview {
display: grid; place-items: center; inline-size: 6rem; block-size: 6rem;
border: 1px solid var(--line); border-radius: .65rem; background: var(--paper);
}
.favicon-preview :is(img, canvas) { inline-size: 4rem; block-size: 4rem; object-fit: contain; }
.favicon-editor-controls { display: grid; gap: .5rem; flex: 1 1 16rem; min-width: 0; }
.favicon-crop-controls { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .65rem; }
.favicon-crop-controls input { width: 100%; margin: 0; accent-color: var(--accent); }
@media (max-width: 32rem) { .favicon-crop-controls { grid-template-columns: minmax(0, 1fr); } }
.picker-actions { justify-content: flex-start; margin-top: .85rem; }
.admin-action-dialog { max-width: min(30rem, calc(100% - 2rem)); }
.admin-action-dialog h2, #media-picker h2 { margin: 0; font-size: 1.45rem; letter-spacing: -.018em; }
.canvas-image-display { display: flex; align-items: center; gap: .35rem; font-size: .85rem; }
.canvas-image-display select, .canvas-format-tools input[type=color] {
.canvas-image-display select {
background: var(--white); border: 1px solid var(--line); border-radius: .35rem;
color: var(--ink); min-height: 2rem; font: inherit; padding: .22rem .35rem;
}
.canvas-format-tools input[type=color] { width: 2.2rem; }
.canvas-format-tools [data-clear-color] svg { width: 1rem; height: 1rem; }
.admin-system-info dl, .admin-license-project, .admin-license-list { max-width: 52rem; }
.studio-layers .studio-layer-tree {
@@ -445,11 +477,98 @@
.studio-layer-row[data-drop=before] { border-block-start-color: var(--accent); }
.studio-layer-row[data-drop=after] { border-block-end-color: var(--accent); }
.studio-layer-row[data-drop=inside], .studio-layer-row[aria-current=true] { background: var(--accent-light); }
.studio-layer-label { min-width: 0; overflow-wrap: anywhere; }
.studio-layer-caption { font-weight: 620; display: flex; align-items: baseline; gap: .3rem; }
.studio-layer-caption small { font: .7rem var(--mono); color: var(--muted); }
.studio-layer-label { min-width: 0; overflow-wrap: anywhere; font: 650 .8rem var(--mono); }
.studio-layer-caption { display: flex; align-items: center; gap: .3rem; }
button.studio-layer-label {
display: inline-flex; align-items: center; gap: .4rem; padding: .2rem .35rem;
border: 0; border-radius: .25rem; background: transparent; color: inherit; cursor: pointer; text-align: start;
}
button.studio-layer-label::before {
content: ""; display: block; flex: none; inline-size: .38rem; block-size: .38rem;
border-block-end: 1.5px solid currentColor; border-inline-end: 1.5px solid currentColor; transform: rotate(-45deg);
}
button.studio-layer-label[aria-expanded=true]::before { transform: rotate(45deg); }
.studio-layer-row[draggable=true] { cursor: grab; }
.studio-layers .studio-layer-actions { display: flex; flex-wrap: wrap; gap: .16rem; margin-block-end: .25rem; }
.studio-layers .studio-layer-actions .button { min-height: 1.7rem; padding: .18rem .26rem; }
.studio-layer-actions .button svg { width: 1rem; height: 1rem; }
.studio-layer-details > summary { font-weight: 500; font-size: .8rem; color: var(--muted); }
.studio-canvas-toolbar { align-items: center; justify-content: flex-start; }
.studio-canvas-toolbar button:not(.button) {
display: inline-grid; place-items: center; min-height: 2.45rem; min-width: 2.45rem; padding: .42rem;
}
.studio-canvas-toolbar button svg, .palette-picker summary > svg { width: 1rem; height: 1rem; }
.studio-canvas-toolbar [aria-label="画布历史"] { margin-inline-start: auto; }
.studio-canvas-toolbar button[data-canvas-color] { gap: .12rem; font-weight: 700; line-height: 1; }
.studio-canvas-toolbar button[data-canvas-color] svg { block-size: .22rem; }
.canvas-format-tools { align-items: center; }
.canvas-format-tools input { font-variant-numeric: tabular-nums; }
.studio-settings-grid, .studio-settings-content { display: grid; gap: .85rem; align-content: start; min-inline-size: 0; }
.studio-settings-grid > fieldset { min-inline-size: 0; align-content: start; align-items: start; margin: 0; }
@media (min-width: 72rem) {
.studio-settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.studio-settings-actions { justify-content: space-between; align-items: center; }
.studio-publication, .studio-publication button > span { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .45rem; }
.studio-publication { font-weight: 600; }
.studio-publication button svg, .canvas-fill button svg { width: 1rem; height: 1rem; }
.palette-name { display: inline-flex; flex-wrap: wrap; align-items: center; gap: .35rem .65rem; }
.palette-swatches { width: 8.3rem; height: .9rem; }
.palette-swatches circle, .canvas-color-swatches circle { stroke: #111a2e33; }
.palette-picker { position: relative; }
.palette-picker summary, .palette-picker-options button {
display: flex; justify-content: space-between; align-items: center; gap: .4rem; min-height: 2.65rem;
border: 1px solid var(--line); border-radius: .45rem; padding: .4rem .6rem;
background: var(--white); color: var(--ink); cursor: pointer; overflow-wrap: anywhere;
}
.palette-picker summary::-webkit-details-marker { display: none; }
.palette-picker summary > svg { flex: none; }
.palette-picker-options {
position: absolute; z-index: 4; inset: calc(100% + .3rem) 0 auto;
display: grid; gap: .25rem; max-height: 13rem; overflow: auto;
padding: .3rem; background: var(--paper); border: 1px solid var(--line); border-radius: .5rem;
box-shadow: 0 .22rem .85rem #16305220;
}
.palette-picker-options button { font: inherit; text-align: start; }
.palette-picker-options button:hover, .palette-picker-options button[aria-pressed=true], .canvas-fill [aria-selected=true] {
background: var(--accent-light); color: var(--accent-deep);
}
.canvas-fill { width: min(31rem, calc(100vw - 2rem)); }
.canvas-fill [data-fill-panel] > label + label, .canvas-fill [data-fill-panel] > :is(.form-grid, label) + :is(label, button) { margin-top: .8rem; }
.canvas-fill input[type=color] { inline-size: 4rem; min-height: 2.3rem; padding: .18rem; }
.canvas-color-swatches { display: flex; flex-wrap: wrap; gap: .2rem; margin-top: .35rem; }
.canvas-color-swatches button {
display: grid; place-items: center; width: 2rem; height: 2rem; padding: .2rem;
border: 1px solid transparent; border-radius: .35rem; background: var(--white); cursor: pointer;
}
.canvas-color-swatches button:is(:hover, :focus-visible) { border-color: var(--accent); }
.canvas-fill .canvas-color-swatches svg { width: 1.4rem; height: 1.4rem; }
.dashboard-page-actions > form > button { min-height: 2.25rem; padding: .28rem .55rem; }
.destructive-action:hover { color: #9c252a; border-color: #e6b6b9; background: #feebeb; }
[data-page-save-feedback] { margin: .35rem 0 0; }
.studio-gradient-preview {
min-height: 5rem; margin-block: .75rem .65rem; border: 1px solid var(--line);
border-radius: .45rem; background-color: var(--paper);
}
.studio-gradient-editor { margin: .55rem .8rem 1rem; }
.studio-gradient-editor .grp-wrapper { border-radius: .35rem; }
.studio-gradient-editor .grp-preview {
position: absolute; inset: 0; border-radius: inherit; outline: 1px solid var(--line); cursor: crosshair;
}
.studio-gradient-editor .grp-handler { height: 100%; width: 0; user-select: none; z-index: 1; }
.studio-gradient-editor .grp-handler-selected { z-index: 2; }
.studio-gradient-editor :is(.grp-handler-close-c, .grp-handler-cp-c) { display: none; }
.studio-gradient-editor .grp-handler-drag {
display: grid; place-items: center; position: absolute; inset: 50% auto auto 0; transform: translate(-50%, -50%);
width: 1.5rem; height: 1.5rem; border: 2px solid white; border-radius: 50%;
box-shadow: 0 0 0 1px #26344e99; cursor: ew-resize; touch-action: none;
}
.studio-gradient-editor .grp-handler-selected .grp-handler-drag { box-shadow: 0 0 0 2px var(--ink); }
.studio-gradient-editor .grp-handler-drag:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.studio-gradient-controls { display: flex; flex-wrap: wrap; gap: .5rem .7rem; align-items: end; }
.studio-gradient-controls button { min-height: 2.35rem; padding: .3rem .6rem; }
.studio-gradient-controls input[type=number] { inline-size: 5.75rem; }
.canvas-fill [data-gradient-angle] input[type=range] { min-height: 2.1rem; padding: 0; accent-color: var(--accent); }
.canvas-fill [data-gradient-angle] output { font-variant-numeric: tabular-nums; }
.studio-background-image-options { margin-top: .75rem; }
+39 -12
View File
@@ -28,20 +28,40 @@ jQuery(function ($) {
$actionDialog.on('click', '[data-action-cancel]', () => $actionDialog.get(0).close());
$('[data-page-layout-editor]').each(function () {
const {pageLayoutEditor: kind, defaultId} = this.dataset;
const {pageLayoutEditor: kind, defaultSlug} = this.dataset;
const $link = $(this);
$('#studio-page-settings').on('change', '[name="' + kind + '_choice"]', function () {
const id = this.value || defaultId;
const slug = this.value ? this.selectedOptions[0]?.dataset.layoutSlug : defaultSlug;
$link.prop('hidden', this.value === 'hidden')
.attr('href', id && this.value !== 'hidden' ? '/admin/pages/layout--' + kind + '-' + id : '/admin/new-page?type=' + kind);
.attr('href', slug ? '/admin/pages/' + slug : '/admin/new-page?type=' + kind);
});
});
$('[data-new-page-type]').on('change', function () {
const ordinary = this.value === 'page';
$(this.form).find('[data-new-page-slug]').prop('hidden', !ordinary)
.find('input').prop({required: ordinary, disabled: !ordinary});
$('[data-open-page-templates]').prop('disabled', !ordinary);
}).trigger('change');
$('[data-palette-picker]').each(function () {
const $picker = $(this);
const $select = $picker.find('select');
const $details = $picker.find('details');
const $options = $picker.find('[data-palette-option]');
function updatePalette() {
const $selected = $options.filter((_, option) => option.dataset.paletteOption === $select.val());
$options.attr('aria-pressed', 'false');
$selected.attr('aria-pressed', 'true');
$picker.find('[data-palette-current]').empty().append($selected.children().clone());
}
$select.on('change.palettePicker', updatePalette).prop('hidden', true);
$details.prop('hidden', false).on('click', '[data-palette-option]', function () {
$select.val(this.dataset.paletteOption).trigger('change');
$details.prop('open', false).find('summary').trigger('focus');
}).on('keydown', (event) => {
if (event.key === 'Escape' && $details.prop('open')) {
event.stopPropagation();
$details.prop('open', false).find('summary').trigger('focus');
}
});
$(document).on('click', (event) => {
if (!$picker.get(0).contains(event.target)) $details.prop('open', false);
});
updatePalette();
});
$('[data-provider-settings]').each(function () {
const $settings = $(this);
const $mode = $settings.find('[name=provider_mode]');
@@ -65,7 +85,8 @@ jQuery(function ($) {
const status = $status.val();
let count = 0;
$pages.each(function () {
const visible = (!status || this.dataset.pageItem === status) && this.dataset.pageLabel.toLowerCase().includes(query);
const visible = (!status || this.dataset.pageItem === status || this.dataset.pagePublicStatus === status)
&& this.dataset.pageLabel.toLowerCase().includes(query);
$(this).prop('hidden', !visible);
if (visible) count++;
});
@@ -89,7 +110,7 @@ jQuery(function ($) {
};
function clearSavedStatus() {
$('[data-save-confirmation]').prop('hidden', true);
$('[data-save-confirmation], [data-page-save-feedback]').prop('hidden', true);
}
if (document.querySelector('[data-save-confirmation]')) {
@@ -181,8 +202,14 @@ jQuery(function ($) {
contentType: multipart ? false : 'application/x-www-form-urlencoded; charset=UTF-8',
dataType: 'json'
}).done(function (response) {
if ($form.is('[data-save-inline]') && response.saved === true && !response.redirect) {
$form.triggerHandler('studio:saved', [response, submitter]);
finish();
if (document.activeElement === document.body) submitter?.focus({preventScroll: true});
return;
}
if (response.redirect) {
$form.triggerHandler('studio:saved');
$form.triggerHandler('studio:saved', [response, submitter]);
window.location.assign(response.redirect);
return;
}
+91
View File
@@ -0,0 +1,91 @@
'use strict';
jQuery(function ($) {
$('[data-favicon-editor]').each(function () {
const $editor = $(this);
const $form = $editor.closest('form');
const $status = $editor.find('[data-favicon-status]');
const $action = $editor.find('[name=favicon_action]');
const $png = $editor.find('[name=favicon_png]');
const $file = $editor.find('[data-favicon-file]');
const $current = $editor.find('[data-favicon-current]');
const $controls = $editor.find('[data-favicon-controls]');
const $zoom = $controls.find('[data-favicon-zoom]');
const $x = $controls.find('[data-favicon-x]');
const $y = $controls.find('[data-favicon-y]');
const $reset = $editor.find('[data-favicon-reset]');
const $canvas = $editor.find('[data-favicon-canvas]');
const canvas = $canvas.get(0);
const context = canvas.getContext('2d');
let image;
let selection = 0;
function draw() {
if (!image) return;
const {naturalWidth: width, naturalHeight: height} = image;
const side = Math.min(width, height) / Number($zoom.val());
const x = (width - side) * Number($x.val()) / 100;
const y = (height - side) * Number($y.val()) / 100;
context.clearRect(0, 0, canvas.width, canvas.height);
context.drawImage(image, x, y, side, side, 0, 0, canvas.width, canvas.height);
$png.val(canvas.toDataURL('image/png').split(',')[1]);
}
async function selectImage(url) {
const currentSelection = ++selection;
const $submit = $form.find(':submit');
$submit.prop('disabled', true);
$status.text('正在读取图片…');
try {
const next = new Image();
next.src = url;
await next.decode();
if (currentSelection !== selection) return;
if (!next.naturalWidth || !next.naturalHeight || Math.max(next.naturalWidth, next.naturalHeight) > 8192) {
throw new Error('Unsupported image dimensions');
}
image = next;
$zoom.val(1);
$x.add($y).val(50);
draw();
$action.val('replace');
$controls.add($canvas).add($reset).prop('hidden', false);
$current.prop('hidden', true);
$status.text('调整裁剪范围后,点击「保存设置」。');
} catch {
if (currentSelection === selection) $status.text('无法读取图片,请选择边长不超过 8192 px 的常见图片格式。');
} finally {
if (currentSelection === selection) $submit.prop('disabled', false);
if (url.startsWith('blob:')) URL.revokeObjectURL(url);
}
}
$file.on('change', function () {
const [file] = this.files;
if (!file) return;
if (file.size > 16 * 1024 * 1024) {
$status.text('请选用不超过 16 MB 的源图片。');
return;
}
selectImage(URL.createObjectURL(file));
});
$controls.on('input', 'input', draw);
$editor.on('click', '[data-favicon-library]', () => {
$('#media-picker').trigger('studio:pick', ['image/', (file) => {
$file.val('');
selectImage(file.url);
}]);
});
$reset.on('click', () => {
++selection;
image = null;
$file.val('');
$action.val('reset');
$png.val('');
$canvas.add($controls).add($reset).prop('hidden', true);
$current.attr('src', $editor.data('defaultIcon')).prop('hidden', false);
$form.find(':submit').prop('disabled', false);
$status.text('保存设置后将恢复默认图标。');
});
});
});
+48
View File
@@ -0,0 +1,48 @@
'use strict';
jQuery(function ($) {
$('[data-head-settings]').each(function () {
const $details = $(this);
const source = $details.find('[data-head-source]').get(0);
const $limit = $details.find('[data-head-limit]');
const encoder = new TextEncoder();
const size = (value) => encoder.encode(value).length;
function fits(current, removed, added) {
const original = size(current);
const next = original - size(removed) + size(added);
$limit.prop('hidden', next <= source.maxLength);
return next <= source.maxLength || next < original;
}
let editor;
$details.on('toggle', () => {
if (!this.open || !window.CodeMirror) return;
if (!editor) {
editor = window.CodeMirror.fromTextArea(source, {
mode: 'htmlmixed', lineNumbers: true, lineWrapping: true, indentUnit: 2, tabSize: 2,
});
editor.getInputField().setAttribute('aria-labelledby', 'head-source-label');
editor.on('beforeChange', (cm, change) => {
if (!fits(cm.getValue(), cm.getRange(change.from, change.to), change.text.join('\n'))) change.cancel();
});
editor.on('change', () => editor.save());
}
editor.refresh();
});
$details.on('click', '[data-head-asset]', function () {
const mime = this.dataset.headAsset;
$('#media-picker').trigger('studio:pick', [mime, (file) => {
const tag = mime === 'text/css'
? $('<link>', {rel: 'stylesheet', href: file.url})
: $('<script>', {src: file.url, defer: true});
const value = tag.prop('outerHTML') + '\n';
if (editor) {
editor.replaceSelection(value);
editor.focus();
} else if (fits(source.value, source.value.slice(source.selectionStart, source.selectionEnd), value)) {
source.setRangeText(value, source.selectionStart, source.selectionEnd, 'end');
source.focus();
}
}]);
});
});
});
+2 -1
View File
@@ -7,6 +7,7 @@
height: 100dvh;
max-height: none;
overflow: auto;
scrollbar-gutter: stable;
overscroll-behavior: contain;
border: 0;
padding: 0;
@@ -33,7 +34,7 @@
.page-template-content h3:focus { outline: none; }
.page-template-back { margin-bottom: 1.15rem; }
.page-template-groups, .page-template-pages { display: grid; gap: .75rem; }
.page-template-groups { grid-template-columns: repeat(auto-fit, minmax(min(100%, 18rem), 1fr)); }
.page-template-groups { grid-template-columns: repeat(auto-fit, minmax(min(100%, 17rem), 1fr)); }
.page-template-pages { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.page-template-detail { display: grid; gap: clamp(1rem, 3vw, 2rem); align-items: start; }
.page-template-card {
+1
View File
@@ -40,6 +40,7 @@ jQuery(function ($) {
$detail.find('[data-template-live]').attr('href', '/admin/page-templates/' + key + '/preview');
$form.find('[name=template], [name=slug]').val(key);
$form.find('[name=name]').val(name);
$form.find('[name=type]').val($('[data-new-page-type]').val() || 'page');
$form.children('.ajax-feedback').prop('hidden', true);
showPanel('detail');
})
Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 28 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

+69 -8
View File
@@ -20,6 +20,8 @@
--line: #cbd7e5;
--accent: #184ed3;
--accent-deep: #153a9b;
--accent-light: #e8efff;
--button-ink: #ffffff;
}
.theme-cobalt .hero {
background: radial-gradient(ellipse at 77% 28%, #c9dafa 0, transparent 45%),
@@ -47,6 +49,7 @@
--accent: #9c3818;
--accent-deep: #78290f;
--accent-light: #ffe7d5;
--button-ink: #231911;
}
.theme-studio .hero {
background: radial-gradient(circle, #9d8269 1px, transparent 1px) 0 0 / 24px 24px, var(--paper);
@@ -68,8 +71,8 @@
}
.theme-studio .app-frame img { border-radius: 0; object-fit: cover; }
.theme-studio .button { border-radius: .15rem; }
.theme-studio .button-primary { color: #231911; background: #f3a578; border-color: #713a24; }
.theme-studio .button-primary:hover { background: #f8ba96; }
.theme-studio .button-primary { background: color-mix(in srgb, var(--accent) 12%, #ffb485); border-color: var(--accent-deep); }
.theme-studio .button-primary:hover { background: color-mix(in srgb, var(--accent) 12%, #ffd0ab); }
.theme-studio .button-outline { background: var(--white); border-color: #827261; }
.template-portfolio { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(1.4rem, 5vw, 4rem); }
.template-portfolio img { width: 100%; aspect-ratio: 3 / 2; object-fit: contain; border: 1px solid var(--line); border-radius: 0; background: var(--paper); }
@@ -84,8 +87,9 @@
--accent: #bdc7ff;
--accent-deep: #dbe1ff;
--accent-light: #343d5e;
--button-ink: #151a30;
}
.theme-dusk .hero { background: radial-gradient(ellipse at 77% 48%, #454255 0, #222639 46%, #191d2b 78%); }
.theme-dusk .hero { background: radial-gradient(ellipse at 77% 48%, #454255 0, var(--paper) 46%, var(--white) 78%); }
.theme-dusk .app-frame {
border: 1px solid #8b869c;
background: #514d6370;
@@ -93,7 +97,6 @@
box-shadow: 0 21px 65px -20px #090a18ab;
}
.theme-dusk .app-frame img { object-fit: cover; }
.theme-dusk .button-primary, .theme-dusk .button-primary:hover { color: #151a30; }
.theme-dusk .button-outline { color: var(--ink); border-color: #8c96b0; }
.theme-dusk .button-outline:hover { color: var(--accent-deep); background: var(--paper); }
.theme-dusk .crumb-divider { color: var(--muted); }
@@ -124,15 +127,15 @@
--accent: #bfe971;
--accent-deep: #d7ffa0;
--accent-light: #2e4233;
--button-ink: #172318;
}
.theme-vantage .hero {
background: radial-gradient(ellipse at 82% 35%, #243b39, transparent 65%),
radial-gradient(circle, #4b6959 1px, transparent 1.4px) 0 0 / 18px 18px, var(--white);
}
.theme-vantage .hero-copy { background: #121b20; padding-block: 1rem; }
.theme-vantage .hero-copy { background: var(--white); padding-block: 1rem; }
.theme-vantage .app-frame { border: 1px solid #618076; border-radius: .2rem; background: #263738; box-shadow: 8px 8px 0 #172e26; }
.theme-vantage .app-frame img, .theme-vantage .button { border-radius: .2rem; }
.theme-vantage .button-primary, .theme-vantage .button-primary:hover { color: #172318; }
.theme-vantage .button-outline { border-color: #7d9b8e; color: var(--ink); }
.theme-vantage .button-outline:hover { background: var(--paper); }
@@ -145,8 +148,9 @@
--accent: #633ab1;
--accent-deep: #4d268e;
--accent-light: #ebdfff;
--button-ink: #ffffff;
}
.theme-ribbon .hero { background: radial-gradient(ellipse at 88% 24%, #d9c5f3, transparent 60%), #f5eff9; }
.theme-ribbon .hero { background: radial-gradient(ellipse at 88% 24%, #d9c5f3, transparent 60%), var(--paper); }
.theme-ribbon .app-frame { border-color: #b9a1db; border-radius: clamp(1.4rem, 4vw, 3rem); background: #fffafc; box-shadow: 0 22px 65px -31px #68489b83; }
.theme-ribbon .app-frame img { border-radius: 1rem; object-fit: cover; }
.theme-ribbon .button { border-radius: 2rem; }
@@ -162,8 +166,9 @@
--accent: #325335;
--accent-deep: #233a27;
--accent-light: #e3ecd9;
--button-ink: #ffffff;
}
.theme-furrow .hero { background: linear-gradient(115deg, #f7f0dd, #eee2c5); }
.theme-furrow .hero { background: linear-gradient(115deg, color-mix(in srgb, var(--paper), var(--white)), var(--paper)); }
.theme-furrow .hero-copy { border-inline-start: .3rem solid #b67e28; padding-inline-start: clamp(1rem, 2.6vw, 2.2rem); }
.theme-furrow :is(h1, h2) { font-family: 'Noto Serif CJK SC', 'Songti SC', Georgia, serif; }
.theme-furrow .app-frame { border: 1px solid #9f946f; border-radius: .3rem; background: #fff8e7; box-shadow: 9px 9px 0 #c6ae7d56; }
@@ -183,6 +188,7 @@
--accent: #944022;
--accent-deep: #692714;
--accent-light: #f2dfc5;
--button-ink: #ffffff;
}
.theme-gather .hero {
background: radial-gradient(circle at 88% 75%, #f6bd53 0 18%, transparent 18.15%),
@@ -199,6 +205,7 @@
--accent: #235d48;
--accent-deep: #163d2d;
--accent-light: #d9eadf;
--button-ink: #ffffff;
}
.theme-market .hero {
background: linear-gradient(125deg, var(--paper) 0 59%, #d7e8dd 59% 76%, #c6ded0 76%);
@@ -216,6 +223,7 @@
--accent: #783849;
--accent-deep: #542136;
--accent-light: #f1dde4;
--button-ink: #ffffff;
}
.theme-dispatch .hero { background: repeating-linear-gradient(90deg, transparent 0 calc(25% - 1px), #d8cbd0 calc(25% - 1px) 25%), var(--paper); }
.theme-dispatch .hero-copy { padding: 1.5rem; background: var(--paper); border-block: 1px solid var(--line); }
@@ -226,3 +234,56 @@
.theme-gather .hero { background: var(--paper); }
.theme-dispatch .hero-copy { padding-inline: .8rem; }
}
.theme-atrium {
--white: #fffdf8;
--paper: #f3ebe1;
--ink: #302521;
--muted: #68534a;
--line: #e0cec1;
--accent: #984631;
--accent-deep: #72321f;
--accent-light: #f3dcd0;
--button-ink: #ffffff;
}
.theme-atrium .hero { background: radial-gradient(ellipse at 78% 28%, #fff9eb, transparent 52%), var(--paper); }
.theme-atrium :is(h1, h2, h3) { font-family: 'Noto Serif CJK SC', 'Songti SC', Georgia, serif; font-weight: 580; }
.theme-atrium .app-frame { border-radius: 46% 46% .5rem .5rem / 44% 44% .5rem .5rem; background: var(--white); }
.theme-atrium .app-frame img { object-fit: cover; }
.theme-atrium .button { border-radius: .25rem; }
.theme-harbor {
--white: #f8faf9;
--paper: #e4efee;
--ink: #183039;
--muted: #476065;
--line: #c1d5d3;
--accent: #176471;
--accent-deep: #154752;
--accent-light: #f4e5b5;
--button-ink: #ffffff;
}
.theme-harbor .hero { background: radial-gradient(ellipse at 87% 90%, #eed88d 0 16%, transparent 16.2%), var(--paper); }
.theme-harbor .app-frame { padding: .4rem; border-color: #719891; border-radius: 1.5rem; background: var(--white); }
.theme-harbor .app-frame img { object-fit: cover; border-radius: 1.15rem; }
.theme-harbor .button { border-radius: 2rem; }
.theme-index {
--white: #fbfaff;
--paper: #efedf6;
--ink: #28213b;
--muted: #5d5570;
--line: #d6cee4;
--accent: #554381;
--accent-deep: #3d2d60;
--accent-light: #e9e1f6;
--button-ink: #ffffff;
}
.theme-index .hero { background: repeating-linear-gradient(0deg, transparent 0 31px, #dfd9ec 31px 32px), var(--paper); }
.theme-index .hero-copy { padding: 1rem; border-inline-start: 3px solid var(--accent); background: var(--paper); }
.theme-index .app-frame { border-radius: .4rem; background: #2c2440; }
.theme-index .button { border-radius: .25rem; }
@media (max-width: 40rem) {
.theme-harbor .hero { background: var(--paper); }
}
+21 -1
View File
@@ -297,7 +297,7 @@ progress { width: 100%; height: .8rem; accent-color: var(--accent); }
.pagination { display: flex; align-items: center; gap: 1rem; margin-top: 1.5rem; }
.empty-state { background: var(--paper); padding: 1rem; border-radius: .6rem; }
.site-footer { padding: clamp(2.5rem, 5.8vw, 5.5rem) 0 2rem; background: #e4ecfc; border-top: 1px solid var(--line); }
.site-footer { padding: clamp(2.5rem, 5.8vw, 5.5rem) 0 2rem; background: var(--accent-light); border-top: 1px solid var(--line); }
.footer-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.6rem clamp(2rem, 7vw, 7rem); }
.footer-company { display: flex; flex-direction: column; align-items: flex-start; }
.footer-logo img { width: clamp(8.125rem, 13vw, 10rem); height: auto; }
@@ -413,6 +413,24 @@ progress { width: 100%; height: .8rem; accent-color: var(--accent); }
.studio-banner { padding: clamp(1.25rem, 4vw, 3.25rem); border-radius: var(--radius); background: var(--accent-light); }
@media (max-width: 44rem) { .studio-split { grid-template-columns: 1fr; } }
.studio-split:is(.studio-split-balanced, .studio-split-cover, .studio-split-guide, .studio-split-story) {
gap: clamp(1rem, 4vw, 3.5rem);
}
.studio-split-cover {
padding: clamp(1rem, 3vw, 2rem); background: var(--paper);
border: 1px solid var(--line); border-radius: var(--radius);
}
.rich .studio-split-cover h3 { font-size: clamp(1.5rem, 3.7vw, 2.6rem); }
.studio-split-guide > img { border: 1px solid var(--line); background: var(--paper); }
.studio-split-story { padding-block: 1rem; border-block: 1px solid var(--line); }
.studio-split-story figure { margin: 0; min-width: 0; }
.studio-alternating { display: grid; gap: clamp(1.5rem, 4vw, 3rem); }
.studio-comparison > :last-child { border-block-start: 3px solid var(--accent); }
@media (min-width: 44.01rem) {
.studio-split-media-left { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
.studio-split-media-right { grid-template-columns: minmax(0, 2fr) minmax(0, 3fr); }
}
:where(img, video, audio, .hero-visual)[class*="studio-media-"] { max-width: 100%; }
:is(.rich, .hero-inner, .editor-preview, .studio-layout-block) [class*="studio-media-"] { width: var(--studio-media-width, auto); }
.studio-media-1 { --studio-media-width: 1%; }
@@ -718,3 +736,5 @@ img.studio-style-display-block, .hero-visual.studio-style-display-block > img {
img.studio-style-display-inline, .hero-visual.studio-style-display-inline > img { display: inline !important; }
img.studio-style-display-inline-block, .hero-visual.studio-style-display-inline-block > img { display: inline-block !important; }
.studio-style-color-theme { color: var(--ink) !important; }
.studio-media-placeholder { display: block; width: min(100%, 24rem); height: auto; }
+170
View File
@@ -0,0 +1,170 @@
'use strict';
window.LaySiteFill = (function ($) {
const hex = '[a-f0-9]{6}';
const anglePattern = /^(0|[1-9]\d{0,2})$/;
const maxStops = 12;
const sizes = {cover: 'cover', contain: 'contain', stretch: '100% 100%', original: 'auto', tile: 'auto'};
const positions = {
c: 'center', tl: 'left top', tc: 'center top', tr: 'right top',
ml: 'left center', mr: 'right center', bl: 'left bottom', bc: 'center bottom', br: 'right bottom'
};
function read(value, decodeImage) {
const solid = value.match(new RegExp('^solid-(' + hex + ')$'));
if (solid) return {kind: 'solid', color: '#' + solid[1]};
const legacy = value.match(new RegExp('^gradient-(\\d{1,3})-(' + hex + ')-(' + hex + ')$'));
if (legacy && anglePattern.test(legacy[1]) && Number(legacy[1]) <= 360) {
return {kind: 'gradient', type: 'linear', angle: Number(legacy[1]), stops: [[0, '#' + legacy[2]], [100, '#' + legacy[3]]]};
}
if (value.startsWith('gradient-')) {
const [, type, ...parts] = value.split('-', 16);
if (!['linear', 'radial'].includes(type)) return null;
const angle = type === 'linear' ? parts.shift() : '90';
if (!anglePattern.test(angle) || Number(angle) > 360 || parts.length < 2 || parts.length > maxStops) return null;
const stops = [];
for (const part of parts) {
const stop = part.match(/^(0|[1-9]\d?|100)_([a-f0-9]{6})$/);
if (!stop || Number(stop[1]) < (stops.at(-1)?.[0] || 0)) return null;
stops.push([Number(stop[1]), '#' + stop[2]]);
}
return {kind: 'gradient', type, angle: Number(angle), stops};
}
if (!value.startsWith('image-')) return null;
const option = value.match(/^image-v2-([a-z]+)-([a-z]+)-([A-Za-z0-9_-]{1,1334})$/);
const [, size, position, payload] = option || ['', 'cover', 'c', value.slice('image-'.length)];
if (!Object.hasOwn(sizes, size) || !Object.hasOwn(positions, position)) return null;
const url = decodeImage(payload);
return url ? {kind: 'image', size, position, url} : null;
}
function declarations(fill) {
if (!fill) return '';
if (fill.kind === 'solid') return 'background:' + fill.color + '!important';
if (fill.kind === 'gradient') {
const direction = fill.type === 'linear' ? fill.angle + 'deg' : 'circle at center';
const stops = fill.stops.map(([position, color]) => color + ' ' + position + '%');
return 'background:' + fill.type + '-gradient(' + [direction, ...stops].join(',') + ')!important';
}
const url = fill.url.replace(/["<>]/g, (character) => '\\' + character.charCodeAt(0).toString(16) + ' ');
return 'background-image:url("' + url + '")!important;background-position:' + positions[fill.position]
+ '!important;background-size:' + sizes[fill.size] + '!important;background-repeat:'
+ (fill.size === 'tile' ? 'repeat' : 'no-repeat') + '!important';
}
function gradientEditor($dialog, colorHex) {
if (typeof window.Grapick !== 'function') return null;
const $track = $dialog.find('[data-gradient-track]');
const $preview = $dialog.find('[data-gradient-preview]');
const $type = $dialog.find('[name=gradient_type]');
const $angleRow = $dialog.find('[data-gradient-angle]');
const $angle = $angleRow.find('input');
const $color = $dialog.find('[name=stop_color]');
const $position = $dialog.find('[name=stop_position]');
const $add = $dialog.find('[data-gradient-add]');
const $remove = $dialog.find('[data-gradient-remove]');
const picker = new window.Grapick({
el: $track.get(0), height: '1.45rem', colorEl: '<span></span>', onValuePos: Math.round,
});
const thumb = (stop) => stop.getEl().querySelector('[data-toggle=handler-drag]');
function sync() {
const selected = picker.getSelected();
const stops = picker.getHandlers();
const radial = $type.val() === 'radial';
$angleRow.prop('hidden', radial).find('output').text($angle.val() + '°');
$preview.get(0).style.backgroundImage = picker.getValue(radial ? 'radial' : 'linear', radial ? 'center' : $angle.val() + 'deg');
if (selected) {
$color.val(colorHex(selected.getColor()));
if (!$position.is(':focus')) $position.val(selected.getPosition());
}
$add.prop('disabled', stops.length >= maxStops);
$remove.prop('disabled', !selected || stops.length <= 2);
for (const stop of stops) {
const color = colorHex(stop.getColor());
const handle = thumb(stop);
handle.style.backgroundColor = color;
$(handle).attr({'aria-label': '色标 ' + color, 'aria-valuenow': stop.getPosition(), 'aria-valuetext': stop.getPosition() + '%'});
}
}
function enableStop(stop) {
const handle = thumb(stop);
$(handle).attr({tabindex: 0, role: 'slider', 'aria-valuemin': 0, 'aria-valuemax': 100})
.on('focus', () => { if (!stop.isSelected()) stop.select(); })
.on('keydown', (event) => {
const offset = {ArrowLeft: -1, ArrowDown: -1, ArrowRight: 1, ArrowUp: 1}[event.key];
if (!offset && !['Home', 'End'].includes(event.key)) return;
event.preventDefault();
const next = event.key === 'Home' ? 0 : event.key === 'End' ? 100
: stop.getPosition() + offset * (event.shiftKey ? 10 : 1);
stop.setPosition(Math.max(0, Math.min(100, next)));
});
}
// Grapick owns pointer dragging and interpolation when a track position is clicked.
picker.on('handler:add', enableStop);
picker.on('handler:select', sync);
picker.on('change', sync);
$track.get(0).addEventListener('click', (event) => {
if (event.target.matches('.grp-preview') && picker.getHandlers().length >= maxStops) event.stopPropagation();
}, true);
$type.add($angle).on('input change', sync);
$color.on('input', function () { picker.getSelected()?.setColor(this.value); });
$position.on('input', function () {
if (this.value !== '' && this.validity.valid) picker.getSelected()?.setPosition(this.valueAsNumber);
}).on('blur', sync);
$add.on('click', () => {
const stops = picker.getHandlers();
if (stops.length >= maxStops) return;
const points = [0, ...stops.map((stop) => stop.getPosition()), 100];
let gap = 1;
for (let i = 2; i < points.length; i++) {
if (points[i] - points[i - 1] > points[gap] - points[gap - 1]) gap = i;
}
const before = stops[Math.max(0, gap - 2)];
const after = stops[Math.min(stops.length - 1, gap - 1)];
const channels = colorHex(before.getColor()).slice(1).match(/../g).map((value, index) => {
const other = colorHex(after.getColor()).slice(1 + 2 * index, 3 + 2 * index);
return Math.round((parseInt(value, 16) + parseInt(other, 16)) / 2).toString(16).padStart(2, '0');
});
const stop = picker.addHandler(Math.round((points[gap] + points[gap - 1]) / 2), '#' + channels.join(''));
thumb(stop).focus();
});
$remove.on('click', () => {
const stops = picker.getHandlers();
const selected = picker.getSelected();
if (!selected || stops.length <= 2) return;
const index = stops.indexOf(selected);
selected.remove();
thumb(stops[Math.min(index, stops.length - 1)]).focus();
});
function setup(initial, accent) {
const fill = initial?.kind === 'gradient' ? initial
: {type: 'linear', angle: 90, stops: [[0, '#ffffff'], [100, accent || '#214ed7']]};
$type.val(fill.type);
$angle.val(fill.angle);
picker.clear({silent: true});
for (const [position, color] of fill.stops) enableStop(picker.addHandler(position, color, false, {silent: true}));
picker.getHandler(0).select();
picker.updatePreview();
}
function value() {
const parts = ['gradient', $type.val()];
if ($type.val() === 'linear') parts.push($angle.val());
for (const stop of picker.getHandlers()) {
parts.push(stop.getPosition() + '_' + colorHex(stop.getColor()).slice(1));
}
return parts.join('-');
}
return {setup, value};
}
return {read, declarations, gradientEditor};
})(jQuery);
+472 -97
View File
@@ -121,7 +121,7 @@ jQuery(function ($) {
$cards.each(function () {
const $card = $(this);
const mime = $card.data('mime');
const matchesType = category === 'other' ? !/^(image|audio|video)\//.test(mime) : mime.startsWith(category);
const matchesType = category === 'other' ? !/^(image|audio|video|text)\//.test(mime) : mime.startsWith(category);
const visible = matchesType && $card.data('search').toLowerCase().includes(query);
$card.prop('hidden', !visible);
if (visible) count++;
@@ -333,6 +333,9 @@ jQuery(function ($) {
const canvasFields = '[data-studio-field="heading"], [data-studio-field="accent"], [data-studio-field="lead"], [data-studio-field="eyebrow"], [data-studio-part="title"], [data-studio-part="lead"], [data-studio-action], [data-studio-nav-index]';
const bodyElements = 'a, article, blockquote, button, details, div, dl, dt, dd, figure, figcaption, footer, h1, h2, h3, h4, h5, h6, header, hr, li, nav, ol, p, pre, progress, section, summary, table, ul, td, th, caption, small';
const mediaTargets = '[data-studio-hero-image], [data-studio-part="body"] img, [data-studio-part="body"] audio, [data-studio-part="body"] video';
const mediaPlaceholder = '/assets/system/media-placeholder.svg';
const textElements = 'a, button, caption, figcaption, h1, h2, h3, h4, h5, h6, label, p, pre, small, span, summary, td, th, li, dt, dd, blockquote';
const fillElements = 'article, aside, blockquote, div, figure, header, footer, main, nav, section, p, a, button, ul, ol, li, dl, table, td, th, details, summary';
const $handle = $studio.find('[data-media-handle]');
const minMediaWidth = Number($handle.attr('aria-valuemin'));
const pathGroups = '[data-studio-navigation], [data-studio-breadcrumbs]';
@@ -377,10 +380,28 @@ jQuery(function ($) {
});
const $toolbar = $studio.find('[data-canvas-toolbar]');
const $commands = $toolbar.find('[data-canvas-command]');
const $textTools = $toolbar.find('[data-canvas-text-tools]');
const $textCommands = $toolbar.find('[data-canvas-text-commands]');
const $insertTools = $toolbar.find('[data-canvas-insert]');
const $background = $toolbar.find('[data-canvas-background]');
const $insertMedia = $commands.filter('[data-canvas-command="media"]');
const $format = $toolbar.find('[data-canvas-format]');
const $fontSize = $toolbar.find('[data-canvas-font-size]');
const $fontPreset = $toolbar.find('[data-font-preset]');
const $color = $toolbar.find('[data-canvas-color]');
const $clearColor = $toolbar.find('[data-clear-color]');
const $letter = $toolbar.find('[data-canvas-letter]');
const $line = $toolbar.find('[data-canvas-line]');
const $fill = $studio.find('[data-canvas-fill]');
const $fillForm = $fill.find('form');
const $fillTabs = $fill.find('[data-fill-tab]');
const $fillError = $fill.find('[data-fill-error]');
const fillInput = (name) => $fillForm.find('[name="' + name + '"]');
const fillControls = window.LaySiteFill;
let gradientEditor;
const colorLabels = JSON.parse($fill.attr('data-color-labels'));
let fillMode;
let fillTarget;
let textColorDialog = false;
const $imageDisplay = $toolbar.find('[data-canvas-image-display]');
const $source = $studio.find('[data-canvas-source]');
const $sourcePart = $source.find('[data-source-part]');
@@ -406,9 +427,10 @@ jQuery(function ($) {
let deletedSections = [];
const propertyInput = (name) => $propertyForm.find('[name="' + name + '"]');
const pageInput = (name) => $settings.find('[name="' + name + '"]');
const settingsSnapshot = () => $settings.serializeArray()
.filter(({name}) => !['csrf', 'canvas_sections', 'canvas_order', 'provider_secret'].includes(name));
let savedSettings = JSON.stringify(settingsSnapshot());
const settingsSnapshot = (includeHead = false) => $settings.serializeArray()
.filter(({name}) => !['csrf', 'version', 'canvas_sections', 'canvas_order', 'provider_secret', 'original_header_id', 'original_footer_id'].includes(name)
&& (includeHead || name !== 'head_html'));
let savedSettings = JSON.stringify(settingsSnapshot(true));
let dialogAction;
let doc;
let activeBody;
@@ -417,7 +439,8 @@ jQuery(function ($) {
let textHost;
let sections = [];
let initialOrder;
let saveComplete = false;
let feedRefresh;
const pendingFeeds = new Set();
let syncPageFromInputs;
let spacingTarget;
let sourceEditor;
@@ -426,19 +449,39 @@ jQuery(function ($) {
const result = {};
for (const name of node.classList) {
const prefix = name.match(stylePattern)?.[1];
if (prefix && (!textOnly || prefix === 'size' || prefix === 'color' || Object.hasOwn(formatOptions, prefix))) result[prefix] = name;
if (prefix && (!textOnly || ['size', 'letter', 'line', 'color'].includes(prefix) || Object.hasOwn(formatOptions, prefix))) result[prefix] = name;
}
return result;
}
function installColor(token) {
if (!colorSheet || canvasColors.has(token) || !/^studio-style-color-[a-f0-9]{6}$/.test(token)) return;
colorSheet.insertRule('.' + token + '{color:#' + token.slice(-6) + '!important}', colorSheet.cssRules.length);
function encodeImage(url) {
return btoa(String.fromCharCode(...new TextEncoder().encode(url))).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
}
function decodeImage(token) {
if (!/^[A-Za-z0-9_-]{1,1334}$/.test(token)) return '';
try {
const bytes = Uint8Array.from(atob(token.replace(/-/g, '+').replace(/_/g, '/')), (byte) => byte.charCodeAt(0));
const url = new TextDecoder('utf-8', {fatal: true, ignoreBOM: true}).decode(bytes);
return bytes.length <= 1000 && safeLink(url, true) && token === encodeImage(url) ? url : '';
} catch {
return '';
}
}
function installStyleRule(token) {
if (!colorSheet || canvasColors.has(token)) return;
const color = token.match(/^studio-style-color-([0-9a-f]{6})$/);
const fillPrefix = 'studio-style-fill-';
const rule = color ? 'color:#' + color[1] + '!important'
: token.startsWith(fillPrefix) && fillControls?.declarations(fillControls.read(token.slice(fillPrefix.length), decodeImage));
if (!rule) return;
colorSheet.insertRule('.' + token + '{' + rule + '}', colorSheet.cssRules.length);
canvasColors.add(token);
}
function installMarkupColors(markup) {
for (const [token] of markup.matchAll(/\bstudio-style-color-[a-f0-9]{6}(?![\w-])/g)) installColor(token);
function installMarkupStyles(markup) {
for (const [token] of markup.matchAll(/\bstudio-style-(?:color|fill)-[a-z0-9_-]+/gi)) installStyleRule(token);
}
function putStyle(node, property, value) {
@@ -446,7 +489,7 @@ jQuery(function ($) {
if (current) node.classList.remove(current);
if (value !== '') {
const token = 'studio-style-' + property + '-' + value;
if (property === 'color') installColor(token);
if (property === 'color' || property === 'fill') installStyleRule(token);
node.classList.add(token);
}
}
@@ -484,7 +527,7 @@ jQuery(function ($) {
const parent = tokens ? doc.createElement('span') : node;
if (tokens) {
parent.className = tokens;
installMarkupColors(tokens);
installMarkupStyles(tokens);
node.append(parent);
}
lineBreaks(text).split('\n').forEach((line, index) => {
@@ -555,7 +598,7 @@ jQuery(function ($) {
function setPageStyle(node, style) {
node.classList.remove(...Object.values(classesOf(node)));
if (style?.classes) {
installMarkupColors(style.classes);
installMarkupStyles(style.classes);
node.classList.add(...style.classes.split(' '));
}
}
@@ -611,15 +654,110 @@ jQuery(function ($) {
pageInput('canvas_sections').val(JSON.stringify(sectionChanges()));
pageInput('canvas_order').val(canvasOrder() === initialOrder ? '' : canvasOrder());
});
$settings.on('studio:saved', () => { saveComplete = true; });
function refreshDynamicSections(keys) {
for (const key of keys) pendingFeeds.add(key);
if (!pendingFeeds.size) return;
feedRefresh?.abort();
const version = pageInput('version').val();
feedRefresh = $.ajax({url: $frame.attr('src'), dataType: 'text', cache: false}).done((html) => {
if (version !== pageInput('version').val()) return;
const preview = doc.createElement('template');
preview.innerHTML = html;
for (const entry of sections) {
if (!pendingFeeds.has(entry.key) || JSON.stringify(entry.feed) !== entry.initialFeed) continue;
const current = entry.fields.body.node;
const saved = preview.content.getElementById(entry.key)?.querySelector('[data-studio-part="body"]');
if (!saved) continue;
const dynamicChildren = (body) => [...body.parentElement.children]
.filter((child) => child !== body && !child.classList.contains('section-heading'));
entry.node.querySelector('[data-studio-module-note]')?.remove();
dynamicChildren(current).forEach((node) => node.remove());
current.before(...dynamicChildren(saved).map((node) => doc.importNode(node, true)));
}
pendingFeeds.clear();
installMarkupStyles(html);
historyObserver?.takeRecords();
scheduleLayers();
});
}
$settings.on('studio:saved', (_event, saved, submitter) => {
if (saved?.saved && saved.redirect) {
$(window).off('beforeunload.studioPage');
return;
}
if (!Array.isArray(saved?.sections)) return;
const versions = new Map(saved.sections.map((section) => [section.key, section]));
const dynamic = [];
for (const entry of sections) {
const revision = versions.get(entry.key);
if (!revision) continue;
const committed = Object.hasOwn(revision, 'body');
// A receipt for an untouched section does not replace its canvas contents.
if (!committed && revision.version !== entry.version) continue;
if (entry.feed && (committed || submitter?.name === 'status'
|| entry.node.querySelector('[data-studio-module-note]'))) dynamic.push(entry.key);
if (!committed) continue;
entry.version = revision.version;
entry.node.dataset.studioSection = revision.version;
entry.source = revision.body;
entry.feed = revision.feed ? JSON.parse(revision.feed) : null;
if (entry.node.classList.contains('section')) entry.node.classList.toggle('network', entry.feed?.mode === 'network');
entry.initialFeed = JSON.stringify(entry.feed);
for (const [field, state] of Object.entries(entry.fields)) {
state.initial = field === 'body' ? cleanBody(state.node) : plainText(state.node);
state.initialAlignment = field === 'body' ? '' : getAlignment(state.node);
}
entry.initialPresentation = JSON.stringify(sectionPresentation(entry));
delete entry.template;
delete entry.copyOf;
}
for (const entry of sections) {
entry.node.querySelector('[data-studio-module-note]')?.remove();
}
deletedSections = [];
initialOrder = canvasOrder();
pageInput('version').val(saved.version);
for (const [field, id] of Object.entries(saved.layoutIds || {})) {
pageInput('original_' + field).val(id ?? '');
}
pageInput('provider_secret').val('');
pageInput('canvas_sections').val('');
pageInput('canvas_order').val('');
savedSettings = JSON.stringify(settingsSnapshot(true));
const published = saved.status === 'published';
const status = published ? '已发布' : '草稿';
$('[data-page-editor-title]').text('编辑 ' + saved.name);
document.title = '编辑 ' + saved.name + ' CMS';
$('[data-page-publication]').text(status).attr('data-published', String(published));
const publicLink = $settings.attr('data-public-page') === '1' && published;
$('[data-page-public]').prop('hidden', !publicLink);
$('[data-page-preview]').prop('hidden', publicLink);
$settings.find('[data-publish-button]').val(published ? 'draft' : 'published')
.find('[data-publication-action]').each(function () {
this.hidden = this.dataset.publicationAction === saved.status;
});
const message = submitter?.name === 'status' ? (published ? '页面已发布。' : '页面已转为草稿。') : '页面已保存。';
const $feedback = submitter && $studio.get(0).contains(submitter) ? $studio : $settings;
$feedback.find('[data-page-save-feedback]').text(message).prop('hidden', false);
// Old snapshots may reference sections deleted by this save.
history.length = 0;
historyIndex = 0;
lastHistoryGroup = null;
captureHistory();
renderLayers();
refreshDynamicSections(dynamic);
});
$settings.on('studio:busy', (_event, busy) => {
$layout.prop('inert', busy);
$settings.prop('inert', busy);
});
$(window).on('beforeunload', (event) => {
if (!saveComplete && (sectionChanges(false).length || pageInput('provider_secret').filter(':enabled').val()
$(window).on('beforeunload.studioPage', (event) => {
if (sectionChanges(false).length || pageInput('provider_secret').filter(':enabled').val()
|| initialOrder !== undefined && canvasOrder() !== initialOrder
|| JSON.stringify(settingsSnapshot()) !== savedSettings)) {
|| JSON.stringify(settingsSnapshot(true)) !== savedSettings) {
event.preventDefault();
event.originalEvent.returnValue = '';
}
@@ -679,7 +817,7 @@ jQuery(function ($) {
activeBody = body;
savedRange = null;
}
$commands.prop('disabled', !activeBody);
syncFormatControls();
}
function editBody(body, range, command, value) {
@@ -711,15 +849,49 @@ jQuery(function ($) {
|| parent.closest('[data-studio-part="body"], [data-studio-section], [data-studio-style-field]');
}
function textTarget(node) {
const styled = styleTarget(node);
if (!styled || styled.matches(mediaTargets)) return null;
if (styled.matches(canvasFields)) return styled;
return styled.closest('[data-studio-part="body"]')
&& (styled.matches(textElements) || [...styled.childNodes].some((child) =>
child.nodeType === 3 && child.textContent.trim())) && styled.textContent.trim() ? styled : null;
}
function formatTarget() {
if (selectedElement && !textTarget(selectedElement)) return null;
if (textRange?.commonAncestorContainer.isConnected && textHost?.contains(textRange.commonAncestorContainer)) {
if (!textRange.collapsed) return textHost;
const anchor = textRange.startContainer;
const element = anchor.nodeType === 1 ? anchor : anchor.parentElement;
if (!textRange.collapsed && selectedText().length) {
return textTarget(element.closest(textElements)) || textHost;
}
if (!selectedElement && doc.activeElement === textHost) {
const anchor = textRange.startContainer;
return styleTarget(editableBodyElement(anchor.parentElement || textHost) || textHost);
return textTarget(element.closest(textElements)) || textTarget(textHost);
}
}
return styleTarget(selectedElement);
return textTarget(selectedElement);
}
function backgroundTarget() {
const node = selectedElement || (textHost?.matches('[data-studio-part="title"]') && doc.activeElement === textHost ? textHost : activeBody);
if (!node || node.matches(mediaTargets)) return null;
if (node.matches('[data-studio-part="title"], [data-studio-part="body"]')) {
return node.closest('[data-studio-section], [data-studio-hero]') || styleTarget(node);
}
const target = styleTarget(node);
return target?.matches(fillElements) ? target : null;
}
function backgroundLabel(target) {
if (target?.hasAttribute('data-studio-section')) return '区块背景填充';
if (target?.hasAttribute('data-studio-hero')) return '首屏背景填充';
return '背景填充';
}
function insertionBody() {
if (activeBody?.isConnected) return activeBody;
return selectedElement?.closest('[data-studio-section]')?.querySelector('[data-studio-part="body"]') || null;
}
function formatState(node, property) {
@@ -749,13 +921,32 @@ jQuery(function ($) {
function syncFormatControls() {
const target = doc && formatTarget();
$format.add($fontSize).prop('disabled', !target);
const canInsertText = Boolean(target && activeBody);
const canInsertMedia = Boolean(insertionBody());
const fill = backgroundTarget();
const fillLabel = backgroundLabel(fill);
$textTools.prop('hidden', !target);
$format.add($fontSize).add($fontPreset).prop('disabled', !target);
$textCommands.prop('hidden', !canInsertText);
$insertTools.prop('hidden', !canInsertMedia && !fill);
$background.prop('hidden', !fill).attr({title: fillLabel, 'aria-label': fillLabel});
$insertMedia.prop('hidden', !canInsertMedia);
const sample = target && (selectedText()[0]?.node || target);
const computed = sample ? doc.defaultView.getComputedStyle(sample.nodeType === 1 ? sample : sample.parentElement) : null;
if (!$fontSize.is(':focus')) $fontSize.val(computed ? Math.round(parseFloat(computed.fontSize)) : '');
$color.add($clearColor).prop('disabled', !target);
const rgb = computed?.color.match(/^rgba?\((\d+), (\d+), (\d+)(?:, [\d.]+)?\)$/);
if (rgb && !$color.is(':focus')) $color.val('#' + rgb.slice(1).map((channel) => Number(channel).toString(16).padStart(2, '0')).join(''));
const element = sample?.nodeType === 1 ? sample : sample?.parentElement;
const computed = element ? doc.defaultView.getComputedStyle(element) : null;
const sizeClass = element && classesOf(element).size;
const size = sizeClass ? sizeClass.slice('studio-style-size-'.length)
: (computed ? String(Math.round(parseFloat(computed.fontSize))) : '');
if (!$fontSize.is(':focus')) $fontSize.val(size);
$fontPreset.val($fontPreset.find('option').toArray().some((option) => option.value === size) ? size : '');
const letter = element && classesOf(element).letter;
const line = element && classesOf(element).line;
const lineHeight = computed && parseFloat(computed.lineHeight) / parseFloat(computed.fontSize);
if (!$letter.is(':focus')) $letter.val(letter ? letter.slice('studio-style-letter-'.length)
: computed && Number.isFinite(parseFloat(computed.letterSpacing)) ? String(Math.round(parseFloat(computed.letterSpacing))) : '');
if (!$line.is(':focus')) $line.val(line ? Number(line.slice('studio-style-line-'.length)) / 10
: Number.isFinite(lineHeight) ? lineHeight.toFixed(1) : '');
$color.find('rect').attr('fill', computed && cssHex(computed.color) || 'currentColor');
$format.each(function () {
$(this).attr('aria-pressed', String(Boolean(sample) && formatState(sample, this.dataset.canvasFormat)));
});
@@ -801,18 +992,124 @@ jQuery(function ($) {
positionSelection();
}
$color.on('change', function () {
if (/^#[0-9a-f]{6}$/i.test(this.value)) applyTextStyle('color', this.value.slice(1).toLowerCase());
});
$clearColor.on('click', () => applyTextStyle('color', ''));
$imageDisplay.on('change', function () {
if (selectedMedia?.matches('img')) putStyle(sizingTarget(), 'display', this.value);
function cssHex(value) {
if (/^#[a-f0-9]{6}$/i.test(value)) return value.toLowerCase();
if (/^#[a-f0-9]{3}$/i.test(value)) return value.toLowerCase().replace(/[a-f0-9]/g, (digit) => digit + digit);
const rgb = value.match(/^rgba?\((\d+), (\d+), (\d+)(?:, [\d.]+)?\)$/);
return rgb ? '#' + rgb.slice(1).map((channel) => Number(channel).toString(16).padStart(2, '0')).join('') : '';
}
function activePalette() {
const palette = pageInput('palette_id').val();
const custom = $settings.find('[data-palette-option]').filter((_, button) => button.dataset.paletteOption === palette)
.find('circle').toArray();
const colors = Object.fromEntries(custom.map((circle) => [circle.dataset.colorKey, circle.getAttribute('fill')]));
const root = doc.querySelector('#main-content') || doc.documentElement;
const styles = doc.defaultView.getComputedStyle(root);
return Object.entries(colorLabels).flatMap(([key, label]) => {
const color = colors[key] || cssHex(styles.getPropertyValue('--' + key).trim()) || (key === 'button-ink' ? '#ffffff' : '');
return color ? [{color, label, key}] : [];
});
}
function showFillTab(mode, focus = false) {
fillMode = mode;
$fillError.prop('hidden', true);
$fillTabs.each(function () {
const selected = this.dataset.fillTab === mode;
$(this).attr('aria-selected', String(selected)).prop('tabIndex', selected ? 0 : -1);
if (selected && focus) this.focus();
});
$fill.find('[data-fill-panel]').each(function () {
this.hidden = this.dataset.fillPanel !== mode;
$(this).find('input, select').prop('disabled', this.hidden);
});
}
function openFill(text) {
fillTarget = text ? formatTarget() : backgroundTarget();
if (!fillTarget?.isConnected) return;
textColorDialog = text;
const computed = doc.defaultView.getComputedStyle(fillTarget);
const palette = activePalette();
const fill = fillControls?.read((classesOf(fillTarget).fill || '').slice('studio-style-fill-'.length), decodeImage);
if (!text) {
gradientEditor ??= fillControls?.gradientEditor($fill, cssHex);
gradientEditor?.setup(fill, palette.find(({key}) => key === 'accent')?.color);
}
const sample = selectedText()[0]?.node.parentElement || fillTarget;
const foreground = cssHex(doc.defaultView.getComputedStyle(sample).color);
fillInput('solid').val(text ? foreground || '#111a2e'
: fill?.kind === 'solid' ? fill.color : cssHex(computed.backgroundColor) || '#ffffff');
fillInput('image').val(fill?.url || '');
fillInput('image_size').val(fill?.size || 'cover');
fillInput('image_position').val(fill?.position || 'c');
$fill.find('[data-fill-title]').text(text ? '文字颜色' : backgroundLabel(fillTarget));
$fill.find('[data-fill-tabs]').prop('hidden', text);
$fill.find('[data-fill-panel="solid"]').attr('aria-labelledby', text ? 'canvas-fill-title' : 'fill-tab-solid');
$fillError.prop('hidden', true);
$fill.find('[data-fill-swatches]').each(function () {
const $row = $(this).empty();
for (const {color, label} of palette) {
const svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
const circle = document.createElementNS(svg.namespaceURI, 'circle');
$(svg).attr({viewBox: '0 0 20 20', 'aria-hidden': 'true'}).append($(circle).attr({cx: '10', cy: '10', r: '8', fill: color}));
$row.append($('<button>', {type: 'button', 'data-swatch': color, title: label + ' ' + color, 'aria-label': label + ' ' + color}).append(svg));
}
});
showFillTab(!text && fill ? fill.kind : 'solid');
$fill.get(0).showModal();
if (text) fillInput('solid').trigger('focus');
}
function applyFill(value) {
if (textColorDialog) applyTextStyle('color', value);
else if (fillTarget?.isConnected) putStyle(fillTarget, 'fill', value);
$fill.get(0).close();
positionSelection();
}
$fill.on('click', '[data-fill-tab]', function () { showFillTab(this.dataset.fillTab); })
.on('keydown', '[data-fill-tab]', function (event) {
const offset = {ArrowLeft: -1, ArrowRight: 1}[event.key];
if (!offset && !['Home', 'End'].includes(event.key)) return;
event.preventDefault();
const index = event.key === 'Home' ? 0 : event.key === 'End' ? $fillTabs.length - 1
: ($fillTabs.index(this) + offset + $fillTabs.length) % $fillTabs.length;
showFillTab($fillTabs.get(index).dataset.fillTab, true);
}).on('click', '[data-swatch]', function () {
fillInput(this.parentElement.dataset.fillSwatches).val(this.dataset.swatch).trigger('input');
}).on('click', '[data-fill-media]', () => {
openPicker('image/', (file) => fillInput('image').val(file.url).trigger('focus'));
}).on('click', '[data-fill-reset]', () => applyFill(''))
.on('click', '[data-fill-close]', () => $fill.get(0).close());
$fillForm.on('submit', (event) => {
event.preventDefault();
if (textColorDialog) {
applyFill(fillInput('solid').val().slice(1));
} else if (fillMode === 'solid') {
applyFill('solid-' + fillInput('solid').val().slice(1));
} else if (fillMode === 'gradient') {
if (!gradientEditor) {
$fillError.text('渐变编辑器暂时无法加载,请刷新页面后重试。').prop('hidden', false);
return;
}
applyFill(gradientEditor.value());
} else {
const url = fillInput('image').val().trim();
if (!safeLink(url, true) || new TextEncoder().encode(url).length > 1000) {
$fillError.text('请选择图片,或输入有效的站内路径或 HTTPS 链接(最多 1000 字节)。').prop('hidden', false);
return;
}
applyFill(['image-v2', fillInput('image_size').val(), fillInput('image_position').val(), encodeImage(url)].join('-'));
}
});
$toolbar.on('mousedown', '[data-canvas-format], [data-clear-color]', (event) => event.preventDefault());
$format.on('click', function () { applyTextStyle(this.dataset.canvasFormat); });
$fontSize.on('change', function () {
if (this.validity.valid) applyTextStyle('size', this.value);
$color.on('click', () => openFill(true));
$background.on('click', () => openFill(false));
$letter.add($line).on('change', function () {
const line = this.hasAttribute('data-canvas-line');
if (this.validity.valid) applyTextStyle(line ? 'line' : 'letter',
this.value === '' ? '' : String(Math.round(this.valueAsNumber * (line ? 10 : 1))));
}).on('keydown', function (event) {
if (event.key === 'Enter') {
event.preventDefault();
@@ -820,20 +1117,56 @@ jQuery(function ($) {
}
});
$imageDisplay.on('change', function () {
if (selectedMedia?.matches('img')) putStyle(sizingTarget(), 'display', this.value);
positionSelection();
});
$toolbar.on('mousedown', '[data-canvas-format], [data-canvas-color], [data-canvas-background]', (event) => event.preventDefault());
$format.on('click', function () { applyTextStyle(this.dataset.canvasFormat); });
$fontPreset.on('change', function () {
applyTextStyle('size', this.value);
});
$fontSize.on('change', function () {
if (this.validity.valid) applyTextStyle('size', this.value === '' ? '' : String(this.valueAsNumber));
}).on('keydown', function (event) {
if (event.key === 'Enter') {
event.preventDefault();
this.blur();
}
});
function syncSpacingPreset($fields) {
const values = $fields.find('[data-spacing-side]').map((_, input) => input.value).get();
const same = values.every((value) => value === values[0]);
const $preset = $fields.find('[data-spacing-preset]');
const presets = $preset.data('spacingPreset');
const index = same && values[0] !== '' ? presets.indexOf(Number(values[0])) : -1;
const label = !same ? '自定义' : (values[0] === '' ? '默认' : values[0] + ' px');
$preset.val(index).attr('aria-valuetext', label);
$fields.find('[data-spacing-readout]').text(label);
}
$elementTools.on('click', '[data-element-spacing]', () => {
spacingTarget = styleTarget(selectedElement);
if (!spacingTarget) return;
const styles = classesOf(spacingTarget);
$spacingForm.find('input').each(function () {
$spacingForm.find('[data-spacing-side]').each(function () {
this.value = styles[this.name]?.slice(('studio-style-' + this.name + '-').length) || '';
});
$spacingForm.find('[data-spacing-preset]').val('');
$spacingForm.find('fieldset').each((_, fields) => syncSpacingPreset($(fields)));
$spacing.get(0).showModal();
});
$spacingForm.on('change', '[data-spacing-preset]', function () {
if (this.value !== '') $(this).closest('fieldset').find('input').val(this.value === 'template' ? '' : this.value);
}).on('input', 'input', function () {
$(this).closest('fieldset').find('[data-spacing-preset]').val('');
$spacingForm.on('input', '[data-spacing-preset]', function () {
const $preset = $(this);
const $fields = $preset.closest('fieldset');
$fields.find('[data-spacing-side]').val($preset.data('spacingPreset')[this.valueAsNumber] ?? '');
syncSpacingPreset($fields);
}).on('input', '[data-spacing-side]', function () {
syncSpacingPreset($(this).closest('fieldset'));
}).on('click', '[data-spacing-reset]', function () {
const $fields = $(this).closest('fieldset');
$fields.find('[data-spacing-side]').val('');
syncSpacingPreset($fields);
});
$elementTools.on('click', '[data-element-parent]', () => {
const parent = parentElement(selectedElement);
@@ -847,7 +1180,9 @@ jQuery(function ($) {
$spacingForm.on('submit', (event) => {
event.preventDefault();
if (spacingTarget?.isConnected) {
$spacingForm.find('input').each(function () { putStyle(spacingTarget, this.name, this.value); });
$spacingForm.find('[data-spacing-side]').each(function () {
putStyle(spacingTarget, this.name, this.value === '' ? '' : String(this.valueAsNumber));
});
}
$spacing.get(0).close();
positionSelection();
@@ -856,14 +1191,11 @@ jQuery(function ($) {
$toolbar.on('mousedown', '[data-canvas-command]', (event) => event.preventDefault());
$toolbar.on('click', '[data-canvas-command]', function () {
const command = this.dataset.canvasCommand;
const body = activeBody;
const body = command === 'media' ? insertionBody() : activeBody;
const range = savedRange?.cloneRange();
const edit = (action, value) => editBody(body, range, action, value);
if (command === 'media') {
openPicker('', async (file) => {
const markup = await mediaMarkup(file);
if (markup) edit('insertHTML', markup);
});
insertMediaPlaceholder(body, range);
} else if (command === 'link') {
openProperties('插入链接', {label: range?.toString() || '', url: ''}, ({label, url}) => {
queueMicrotask(() => {
@@ -927,7 +1259,7 @@ jQuery(function ($) {
const preview = new DOMParser().parseFromString(html, 'text/html');
const replacement = $(preview.body).children(selector).get(0);
if (!replacement) return;
installMarkupColors(replacement.outerHTML);
installMarkupStyles(replacement.outerHTML);
$target.replaceWith(doc.importNode(replacement, true));
rendered = choice;
});
@@ -968,6 +1300,13 @@ jQuery(function ($) {
syncImage();
$image.attr({tabindex: '0', role: 'button', 'aria-label': '编辑首屏图片'});
heroControls.set('image', () => {
if (!pageInput('image').val()) {
pageInput('image').val(mediaPlaceholder);
syncImage();
selectElement($image.get(0));
$image.get(0).scrollIntoView({block: 'nearest'});
return;
}
openProperties('首屏图片', {url: pageInput('image').val(), alt: pageInput('alt').val()}, ({url, alt}) => {
pageInput('image').val(url);
pageInput('alt').val(alt);
@@ -1036,7 +1375,14 @@ jQuery(function ($) {
});
pageInput('palette_id').on('change.canvas', function () {
$doc.find('[data-page-palette]').remove();
if (this.value) $('<link>', {rel: 'stylesheet', href: '/palette/' + this.value + '.css', 'data-page-palette': ''}).appendTo($doc.find('head'));
const option = this.selectedOptions[0];
const href = option?.dataset.paletteCss;
$doc.find('#main-content').attr('data-region-palette', option?.hasAttribute('data-palette-region') ? option.value : null);
if (href) {
$('<link>', {rel: 'stylesheet', href, 'data-page-palette': ''})
.one('load', syncFormatControls).appendTo($doc.find('head'));
} else syncFormatControls();
pageInput('palette_id').trigger('change.palettePicker');
});
syncActions();
@@ -1165,7 +1511,7 @@ jQuery(function ($) {
syncPageFromInputs = () => {
const presentation = pagePresentation();
$heroSource.html(presentation.heroHtml ?? '');
installMarkupColors(presentation.heroHtml ?? '');
installMarkupStyles(presentation.heroHtml ?? '');
$doc.find('[data-studio-field]').each(function () {
const field = this.dataset.studioField;
paintText(this, pageInput(field).val(), presentation[field]?.runs);
@@ -1190,6 +1536,10 @@ jQuery(function ($) {
function editResource(node) {
const tag = node.localName;
if (node.classList.contains('studio-media-placeholder')) {
choosePlaceholderMedia(node);
return;
}
if (node.matches('a.studio-member-slot') && $settings.find('[data-shared-auth]').length) {
syncMemberSettings();
$settings.find('[data-shared-auth]').prop('open', true).find('[name=provider_mode]').trigger('focus');
@@ -1407,6 +1757,7 @@ jQuery(function ($) {
$elementTools.find('[data-element-source]').prop('hidden', !node?.matches('[data-studio-section], [data-studio-hero]'));
selectedMedia = node?.matches(mediaTargets) ? node : null;
$sizing.prop('hidden', !selectedMedia);
$imageDisplay.closest('label').prop('hidden', !selectedMedia?.matches('img'));
$imageDisplay.prop('disabled', !selectedMedia?.matches('img')).val(classesOf(sizingTarget() || doc.documentElement).display?.slice('studio-style-display-'.length) || '');
$layers.find('.studio-layer-row[aria-current]').removeAttr('aria-current');
if (node) {
@@ -1544,8 +1895,8 @@ jQuery(function ($) {
event.preventDefault();
const categories = moduleInput('feed_categories[]').filter(':checked').map((_, node) => node.value).get();
const title = moduleInput('module_title').val().trim();
if (!title || !categories.length) {
$moduleDialog.find('[data-module-error]').text('请填写标题并至少选择一个分类。').prop('hidden', false);
if (!title) {
$moduleDialog.find('[data-module-error]').text('请填写模块标题。').prop('hidden', false);
return;
}
const {node, fields} = editedModule;
@@ -1566,7 +1917,7 @@ jQuery(function ($) {
function refreshLayerTitle(section) {
const title = plainText(section.fields.title.node) || '未命名区块';
$layers.find('.studio-layer-row').filter((_, row) => $(row).data('canvasNode') === section.node)
.find('.studio-layer-label').text(title);
.find('.studio-layer-label').attr('title', title);
}
function isHeroVisible() {
@@ -1703,7 +2054,7 @@ jQuery(function ($) {
});
selectElement(null);
changed.forEach(([key, {node}], index) => {
installMarkupColors(markup[index]);
installMarkupStyles(markup[index]);
node.replaceChildren(fragments[index]);
if (node.dataset.studioPlaceholder) node.toggleAttribute('data-studio-empty', !plainText(node));
if (key === 'hero') {
@@ -1730,6 +2081,7 @@ jQuery(function ($) {
let draggedLayer;
let dropHint;
let layerTimer;
let layerBranchId = 0;
const layerActions = {
jump: ['target', '定位'], up: ['up', '上移'], down: ['down', '下移'],
delete: ['delete', '删除'], source: ['code', '编辑 HTML'],
@@ -1748,18 +2100,6 @@ jQuery(function ($) {
&& !child.matches('meta, template, [data-studio-module-note]') && (authored || !child.matches('[aria-hidden="true"]')));
}
function layerName(node) {
const structure = {'wrap': '内容宽度容器', 'section-heading': '标题与简介', 'hero-copy': '首屏文案',
'hero-inner': '首屏布局', 'hero-actions': '首屏按钮', 'section-nav-inner': '目录链接'};
if (node.dataset.studioPart === 'body') return '区块正文';
const group = Object.keys(structure).find((name) => node.classList.contains(name));
if (group) return structure[group];
const tag = node.localName;
const authoredLabel = node.matches('img') ? node.alt : node.firstChild?.nodeType === 3 ? node.firstChild.textContent.trim() : '';
const types = {img: '图片', a: '链接', nav: '导航', div: '容器', section: '分区', p: '段落', br: '换行'};
return (authoredLabel || node.getAttribute('aria-label') || types[tag] || tag).slice(0, 38);
}
function layerContext(node) {
if (!node?.isConnected) return null;
const entry = sections.find((section) => section.node === node);
@@ -1848,9 +2188,10 @@ jQuery(function ($) {
.data('canvasNode', node).appendTo($item);
if (node === selectedElement) $row.attr('aria-current', 'true');
const $caption = $('<div>', {class: 'studio-layer-caption'}).appendTo($row);
if (node.hidden) $('<small>', {text: '隐藏'}).appendTo($caption);
$('<span>', {class: 'studio-layer-label', text: label || layerName(node)}).appendTo($caption);
if (!root) $('<small>').text(node.localName).appendTo($caption);
const children = layerChildren(node).filter((child) => !child.hasAttribute('data-studio-section'));
const $tag = $(children.length ? '<button>' : '<span>', {
class: 'studio-layer-label', text: '<' + node.localName + '>', title: label || node.getAttribute('aria-label') || '',
}).appendTo($caption);
if (entry && entry.feed !== null) $('<span>', {class: 'studio-dynamic-badge', text: '动态'}).appendTo($caption);
const $actions = $('<div>', {class: 'studio-layer-actions'}).appendTo($row);
$actions.append(layerButton('jump'));
@@ -1865,33 +2206,28 @@ jQuery(function ($) {
$('<a>', {class: 'button button-outline', href: $settings.attr('action') + '/' + entry.key,
title: '区块设置', 'aria-label': '区块设置'}).append(icon).appendTo($actions);
}
const children = layerChildren(node).filter((child) => !child.hasAttribute('data-studio-section'));
if (!children.length) return;
const $details = $('<details>', {class: 'studio-layer-details',
open: expandedLayers.has(node) || root && !closedLayers.has(node)}).appendTo($item);
const $summary = $('<summary>').text('子图层 · ' + children.length).appendTo($details);
function showChildren() {
if ($details.children('ul').length) return;
const $children = $('<ul>', {class: 'studio-layer-tree'}).appendTo($details);
for (const child of children) layerRow($children, child);
const branchId = 'studio-layer-branch-' + ++layerBranchId;
const $branch = $('<ul>', {id: branchId, class: 'studio-layer-tree', hidden: true}).appendTo($item);
function disclose(open) {
$tag.attr('aria-expanded', String(open));
$branch.prop('hidden', !open);
if (open && !$branch.children().length) {
for (const child of children) layerRow($branch, child);
}
}
function syncDisclosure() {
if ($details.prop('open')) {
$tag.attr({type: 'button', 'aria-controls': branchId}).on('click', () => {
const open = $branch.prop('hidden');
if (open) {
expandedLayers.add(node);
closedLayers.delete(node);
showChildren();
} else {
expandedLayers.delete(node);
closedLayers.add(node);
}
}
$summary.on('click', (event) => {
event.preventDefault();
$details.prop('open', !$details.prop('open'));
syncDisclosure();
disclose(open);
});
$details.on('toggle', () => { if ($details.get(0).isConnected) syncDisclosure(); });
if ($details.prop('open')) showChildren();
disclose(expandedLayers.has(node) || root && !closedLayers.has(node));
}
function renderLayers() {
@@ -2116,10 +2452,45 @@ jQuery(function ($) {
editBody(body, insertion, 'insertHTML', template.innerHTML);
}
function insertMediaPlaceholder(body, range, mime = '') {
if (!body?.isConnected) return;
const type = mime.split('/')[0];
const node = doc.createElement('img');
node.src = mediaPlaceholder;
node.alt = {image: '图片占位', video: '视频占位', audio: '音频占位'}[type] || '媒体占位';
node.className = 'studio-media-placeholder' + (type ? ' studio-media-placeholder-' + type : '');
const existing = new Set(body.querySelectorAll('img.studio-media-placeholder'));
insertInBody(node.outerHTML, body, range);
const inserted = [...body.querySelectorAll('img.studio-media-placeholder')].find((image) => !existing.has(image));
if (!inserted) return;
selectBody(body);
selectElement(inserted);
inserted.scrollIntoView({block: 'nearest'});
$studio.find('[data-canvas-status]').text('已插入占位图。双击占位图或选择「替换媒体」添加文件。');
}
function choosePlaceholderMedia(placeholder) {
const type = ['image', 'video', 'audio'].find((kind) => placeholder.classList.contains('studio-media-placeholder-' + kind));
openPicker(type ? type + '/' : '', async (file) => {
const markup = await mediaMarkup(file);
if (!markup || !placeholder.isConnected) return;
const template = doc.createElement('template');
template.innerHTML = markup;
const media = template.content.firstElementChild;
for (const token of placeholder.classList) {
if (!token.startsWith('studio-media-placeholder') && (!media.matches('a') || !mediaWidthClass.test(token))) {
media.classList.add(token);
}
}
placeholder.replaceWith(media);
selectElement(media);
});
}
$presets.on('mousedown', '[data-canvas-template], [data-canvas-element]', (event) => event.preventDefault());
$presets.on('click', '[data-canvas-element]', function () {
const $status = $presets.find('[data-element-status]');
const body = activeBody;
const body = this.dataset.elementMime ? insertionBody() : activeBody;
const range = savedRange?.cloneRange();
if (!body) {
$status.text('请先在画布中选中要插入的正文。');
@@ -2132,7 +2503,8 @@ jQuery(function ($) {
$status.text('已插入' + $(this).text() + '。');
};
if (this.dataset.elementMime) {
openPicker(this.dataset.elementMime, async (file) => add(await mediaMarkup(file)));
insertMediaPlaceholder(body, range, this.dataset.elementMime);
$status.text('已插入' + $(this).text().trim() + '占位图。');
} else {
add($presets.find('template[data-element="' + this.dataset.canvasElement + '"]').get(0).innerHTML);
}
@@ -2175,7 +2547,10 @@ jQuery(function ($) {
scopeTemplateIds(body, id);
if (feed) {
section.dataset.studioDynamic = '';
section.dataset.studioFeed = feed;
const config = JSON.parse(feed);
const available = new Set(moduleInput('feed_categories[]').map((_, input) => input.value).get());
config.categories = config.categories.filter((category) => available.has(category));
section.dataset.studioFeed = JSON.stringify(config);
section.tabIndex = 0;
noteModule(section, '保存页面后将加载动态内容。');
}
@@ -2213,7 +2588,7 @@ jQuery(function ($) {
})),
deleted: [...deletedSections],
};
const key = JSON.stringify(state, (name, value) => name === 'entry' ? undefined : value);
const key = JSON.stringify(state, (name, value) => ['entry', 'note'].includes(name) ? undefined : value);
if (history[historyIndex]?.key === key) return;
const time = performance.now();
history.splice(historyIndex + 1);
@@ -2330,7 +2705,7 @@ jQuery(function ($) {
initialOrder = canvasOrder();
syncMemberSettings();
syncPagePresentation();
savedSettings = JSON.stringify(settingsSnapshot());
savedSettings = JSON.stringify(settingsSnapshot(true));
history.length = 0;
historyIndex = 0;
lastHistoryGroup = null;
Binary file not shown.

After

Width:  |  Height:  |  Size: 136 KiB

@@ -0,0 +1,8 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 360">
<rect x="1" y="1" width="638" height="358" rx="14" fill="#f1f5fa" stroke="#c5d1e1" stroke-width="2" stroke-dasharray="8 6"/>
<g fill="none" stroke="#566c91" stroke-width="3" stroke-linecap="round" stroke-linejoin="round">
<rect x="290" y="157" width="60" height="46" rx="6"/>
<circle cx="309" cy="171" r="4"/>
<path d="m291 194 13-11 9 7 13-12 23 19"/>
</g>
</svg>

After

Width:  |  Height:  |  Size: 446 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

File diff suppressed because one or more lines are too long
+8
View File
@@ -0,0 +1,8 @@
/**
* Minified by jsDelivr using Terser v5.39.0.
* Original file: /npm/codemirror@5.65.21/mode/htmlmixed/htmlmixed.js
*
* Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
*/
!function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror"),require("../xml/xml"),require("../javascript/javascript"),require("../css/css")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","../xml/xml","../javascript/javascript","../css/css"],t):t(CodeMirror)}((function(t){"use strict";var e={script:[["lang",/(javascript|babel)/i,"javascript"],["type",/^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i,"javascript"],["type",/./,"text/plain"],[null,null,"javascript"]],style:[["lang",/^css$/i,"css"],["type",/^(text\/)?(x-)?(stylesheet|css)$/i,"css"],["type",/./,"text/plain"],[null,null,"css"]]};var a={};function n(t,e){var n=t.match(function(t){var e=a[t];return e||(a[t]=new RegExp("\\s+"+t+"\\s*=\\s*('|\")?([^'\"]+)('|\")?\\s*"))}(e));return n?/^\s*(.*?)\s*$/.exec(n[2])[1]:""}function l(t,e){return new RegExp((e?"^":"")+"</\\s*"+t+"\\s*>","i")}function r(t,e){for(var a in t)for(var n=e[a]||(e[a]=[]),l=t[a],r=l.length-1;r>=0;r--)n.unshift(l[r])}t.defineMode("htmlmixed",(function(a,o){var i=t.getMode(a,{name:"xml",htmlMode:!0,multilineTagIndentFactor:o.multilineTagIndentFactor,multilineTagIndentPastTag:o.multilineTagIndentPastTag,allowMissingTagName:o.allowMissingTagName}),c={},s=o&&o.tags,u=o&&o.scriptTypes;if(r(e,c),s&&r(s,c),u)for(var m=u.length-1;m>=0;m--)c.script.unshift(["type",u[m].matches,u[m].mode]);function d(e,r){var o,s=i.token(e,r.htmlState),u=/\btag\b/.test(s);if(u&&!/[<>\s\/]/.test(e.current())&&(o=r.htmlState.tagName&&r.htmlState.tagName.toLowerCase())&&c.hasOwnProperty(o))r.inTag=o+" ";else if(r.inTag&&u&&/>$/.test(e.current())){var m=/^([\S]+) (.*)/.exec(r.inTag);r.inTag=null;var f=">"==e.current()&&function(t,e){for(var a=0;a<t.length;a++){var l=t[a];if(!l[0]||l[1].test(n(e,l[0])))return l[2]}}(c[m[1]],m[2]),g=t.getMode(a,f),p=l(m[1],!0),h=l(m[1],!1);r.token=function(t,e){return t.match(p,!1)?(e.token=d,e.localState=e.localMode=null,null):function(t,e,a){var n=t.current(),l=n.search(e);return l>-1?t.backUp(n.length-l):n.match(/<\/?$/)&&(t.backUp(n.length),t.match(e,!1)||t.match(n)),a}(t,h,e.localMode.token(t,e.localState))},r.localMode=g,r.localState=t.startState(g,i.indent(r.htmlState,"",""))}else r.inTag&&(r.inTag+=e.current(),e.eol()&&(r.inTag+=" "));return s}return{startState:function(){return{token:d,inTag:null,localMode:null,localState:null,htmlState:t.startState(i)}},copyState:function(e){var a;return e.localState&&(a=t.copyState(e.localMode,e.localState)),{token:e.token,inTag:e.inTag,localMode:e.localMode,localState:a,htmlState:t.copyState(i,e.htmlState)}},token:function(t,e){return e.token(t,e)},indent:function(e,a,n){return!e.localMode||/^\s*<\//.test(a)?i.indent(e.htmlState,a,n):e.localMode.indent?e.localMode.indent(e.localState,a,n):t.Pass},innerMode:function(t){return{state:t.localState||t.htmlState,mode:t.localMode||i}}}}),"xml","javascript","css"),t.defineMIME("text/html","htmlmixed")}));
//# sourceMappingURL=/sm/e2c7ccb5e794d8515250b328c4947e850defb14ee2247c63cd3549e4879addb0.map
File diff suppressed because one or more lines are too long
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) Artur Arseniev
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 OR OTHER DEALINGS IN THE
SOFTWARE.
File diff suppressed because one or more lines are too long