dsh-folia 4.26.0-pre.69 → 4.26.0-pre.70

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.
Files changed (2) hide show
  1. package/lib/client.js +240 -1
  2. package/package.json +1 -1
package/lib/client.js CHANGED
@@ -437,6 +437,13 @@ window.__ModuleLoader__.load({
437
437
  "未配置 · 场景实时渲染贴图走程序化复刻": "Not configured · Scene live rendering textures fall back to procedural recreation",
438
438
  "指向 Wallpaper Engine 安装目录的 assets(或其拷贝)": "Points to the assets folder of the Wallpaper Engine installation (or a copy of it)",
439
439
  "上传中…": "Uploading…",
440
+ // 侧栏快捷面板「壁纸」页签的本地上传入口(pre.70)—— 与设置页上传同一条链路,
441
+ // 新词按任务单归在 panel 域(守卫只对账键集,不按文件分域)。
442
+ "⬆ 上传本地": "⬆ Upload local",
443
+ "上传本地": "Upload local",
444
+ "上传中 {done}/{total}…": "Uploading {done}/{total}…",
445
+ "拖到这里上传": "Drop here to upload",
446
+ "仅支持 JPG / PNG / MP4": "Only JPG / PNG / MP4",
440
447
  "已上传 {count} 个": "Uploaded {count} item(s)",
441
448
  "支持 JPG / PNG / MP4,及含 project.json 的 WE 壁纸目录": "Supports JPG / PNG / MP4, and WE wallpaper folders containing project.json",
442
449
  "移除这个自定义壁纸(会再问一次,且会删除本地文件)": "Remove this custom wallpaper (asks again and deletes the local file).",
@@ -5909,6 +5916,26 @@ window.__ModuleLoader__.load({
5909
5916
  .we-qp__viewbar .we-qp__search { flex: 1 1 auto; min-width: 0; max-width: 300px; width: auto; }
5910
5917
  .we-qp__viewbar .we-qp__viewtabs { flex: none; margin-left: auto; }
5911
5918
  .we-qp__viewbar .we-qp__filter { flex: 1 1 0; min-width: 0; max-width: 160px; }
5919
+ /* 本地上传入口(pre.70):搜索框右边的窄按钮。flex:none + 搜索框 min-width:0 ⇒
5920
+ 窄侧栏里先缩搜索框,按钮不会被挤出行;视口窄到手机宽度(≤420px)时只露图标,
5921
+ 完整文案留在 title / aria-label 里(键盘仍可 Tab 到它 —— 它是真 <button>)。 */
5922
+ .we-qp__viewbar .we-qp__uploadbtn { flex: none; padding: 0 8px; font-size: 11px; }
5923
+ .we-qp__uploadbtn-icon { display: none; }
5924
+ @media (max-width: 420px) {
5925
+ .we-qp__uploadbtn-label { display: none; }
5926
+ .we-qp__uploadbtn-icon { display: inline; font-size: 13px; }
5927
+ }
5928
+ .we-qp__uploadfile { display: none; }
5929
+ /* 上传状态行:占满搜索行下面一整行;全空时渲染器返回 null(不占高度)。 */
5930
+ .we-qp__uploadstatus {
5931
+ flex: 1 1 100%; display: flex; flex-direction: column; gap: 2px; min-width: 0;
5932
+ }
5933
+ .we-qp__uploadstatus .we-picker__hint { font-size: 11px; }
5934
+ /* 拖拽悬停:整块列表区给一圈 accent 虚线,告诉用户"松手就传到这"。 */
5935
+ .we-qp__library--drop {
5936
+ outline: 1px dashed var(--we-accent, var(--dsw-alias-border-l2, rgba(128, 128, 128, 0.55)));
5937
+ outline-offset: 4px; border-radius: 8px;
5938
+ }
5912
5939
  /* 列表 / 卡片:标签式切换 —— 复用 .we-tabs 的滑动胶囊做激活指示,但去掉分段底与
5913
5940
  描边(用户口径:不要默认背景);页签收成内容宽(两枚都是两字,等宽成立,
5914
5941
  胶囊 (100%-6px)/2 的等分算式与 3px 内衬原样沿用)。 */
@@ -26542,6 +26569,119 @@ window.__ModuleLoader__.load({
26542
26569
  ];
26543
26570
  }
26544
26571
 
26572
+ // ── 侧栏「壁纸」页签的本地上传入口(pre.70)────────────────────────────────
26573
+ // 复用 `src/client.js` 的 `uploadWallpaperFile(file)`(同一 bundle 作用域;设置页的
26574
+ // 「自定义」入口也走它)—— 这里**不重写上传**,只做"多选 + 串行 + 进度 + 拖拽"这层壳。
26575
+ // 允许的格式必须与宿主 `UPLOAD_EXT`(lib/media/media-dirs.js)一致:mp4 / jpeg / png。
26576
+ // webp / gif / avif / webm **不放开** —— 宿主那张表没有它们,前端收得下只会换来 415。
26577
+ const QP_UPLOAD_ACCEPT = ".jpg,.jpeg,.png,.mp4";
26578
+
26579
+ /**
26580
+ * 串行上传一批文件:一个完成再发下一个。
26581
+ *
26582
+ * 为什么必须串行:`uploadWallpaperFile` 用的是共享 transient(`uploading` / `uploadError` /
26583
+ * `uploadNote`),并发会把彼此的状态互相覆盖 —— 进度条会跳、错误会被后一个文件的
26584
+ * "开始上传"清掉。依赖全经参数注入,因此 `test/verify-qp-upload.mjs` 能用假实现直接
26585
+ * 执行这条编排(顺序 / 进度 / 失败不中断 / 成功回调次数)。
26586
+ */
26587
+ async function qpUploadFilesSequential(files, deps) {
26588
+ const list = Array.from(files || []).filter((f) => f && typeof f.name === "string" && f.name);
26589
+ const total = list.length;
26590
+ const opts = deps || {};
26591
+ const uploadOne = typeof opts.uploadOne === "function" ? opts.uploadOne : async () => ({ ok: true });
26592
+ const onProgress = typeof opts.onProgress === "function" ? opts.onProgress : null;
26593
+ const onSuccess = typeof opts.onSuccess === "function" ? opts.onSuccess : null;
26594
+ let succeeded = 0;
26595
+ let failed = 0;
26596
+ for (let i = 0; i < total; i++) {
26597
+ if (onProgress) onProgress({ busy: true, done: i, total });
26598
+ const result = await uploadOne(list[i], i);
26599
+ if (result && result.ok === false) {
26600
+ failed++;
26601
+ } else {
26602
+ succeeded++;
26603
+ if (onSuccess) onSuccess(list[i], i, result);
26604
+ }
26605
+ }
26606
+ if (onProgress) onProgress({ busy: false, done: total, total });
26607
+ return { total, succeeded, failed };
26608
+ }
26609
+
26610
+ /** 拖拽事件 → 文件数组(不是拖文件 / 没有文件时返回空数组)。 */
26611
+ function qpDroppedFiles(dataTransfer) {
26612
+ if (!dataTransfer || !dataTransfer.files) return [];
26613
+ return Array.from(dataTransfer.files).filter((f) => f && typeof f.name === "string" && f.name);
26614
+ }
26615
+
26616
+ /** 进度文案:「上传中 1/3…」—— `done` 是**已完成**数,屏上显示正在传的那一个。 */
26617
+ function qpUploadProgressText(state) {
26618
+ const total = Math.max(1, Number(state && state.total) || 0);
26619
+ const done = Math.min(total, Math.max(0, Number(state && state.done) || 0) + 1);
26620
+ return weT("上传中 {done}/{total}…", { done, total });
26621
+ }
26622
+
26623
+ /**
26624
+ * 「⬆ 上传本地」按钮 + 隐藏的多选 file input。
26625
+ * 按钮是真 `<button>`(Tab 可达、Enter/Space 可点),点它转去 `.click()` 隐藏 input;
26626
+ * 不用 `<label>` 包 input —— label 默认不可聚焦,键盘用户到不了这个入口。
26627
+ */
26628
+ function QpUploadControl(props) {
26629
+ const inputRef = React.useRef(null);
26630
+ const busy = Boolean(props && props.busy);
26631
+ const openPicker = () => {
26632
+ if (busy) return;
26633
+ const el = inputRef.current;
26634
+ if (el) el.click();
26635
+ };
26636
+ return React.createElement(React.Fragment, null,
26637
+ React.createElement("button", {
26638
+ type: "button",
26639
+ className: "we-picker__btn we-qp__uploadbtn",
26640
+ "data-we-qp-upload": "1",
26641
+ disabled: busy,
26642
+ title: weT("上传本地"),
26643
+ "aria-label": weT("上传本地"),
26644
+ onClick: openPicker,
26645
+ },
26646
+ React.createElement("span", { className: "we-qp__uploadbtn-icon", "aria-hidden": "true" }, "⬆"),
26647
+ React.createElement("span", { className: "we-qp__uploadbtn-label" }, weT("⬆ 上传本地")),
26648
+ ),
26649
+ React.createElement("input", {
26650
+ ref: inputRef,
26651
+ className: "we-qp__uploadfile",
26652
+ type: "file",
26653
+ multiple: true,
26654
+ accept: QP_UPLOAD_ACCEPT,
26655
+ disabled: busy,
26656
+ tabIndex: -1,
26657
+ "aria-hidden": "true",
26658
+ onChange: (e) => {
26659
+ // 先把 FileList 拷成数组再清 value:FileList 是活引用,清 value 后可能一起空掉。
26660
+ const picked = Array.from(e.target.files || []);
26661
+ e.target.value = "";
26662
+ if (picked.length && props && typeof props.onFiles === "function") props.onFiles(picked);
26663
+ },
26664
+ }),
26665
+ );
26666
+ }
26667
+
26668
+ /** 上传状态行(搜索行下方):进度 / 错误 / 重复提示 / 拖拽提示;全空时**不占高度**。 */
26669
+ function qpRenderUploadStatus(sel, state, dragActive) {
26670
+ const busy = Boolean(state && state.busy);
26671
+ const hasError = !busy && Boolean(sel.uploadError);
26672
+ const hasNote = !busy && !hasError && Boolean(sel.uploadNote);
26673
+ if (!busy && !hasError && !hasNote && !dragActive) return null;
26674
+ return React.createElement("div", {
26675
+ className: "we-qp__uploadstatus", role: "status", "aria-live": "polite",
26676
+ },
26677
+ busy ? React.createElement("span", { className: "we-picker__hint" }, qpUploadProgressText(state)) : null,
26678
+ hasError ? React.createElement("div", { className: "we-picker__error" }, sel.uploadError) : null,
26679
+ hasNote ? React.createElement("div", { className: "we-picker__note" }, sel.uploadNote) : null,
26680
+ dragActive ? React.createElement("span", { className: "we-picker__hint" }, weT("拖到这里上传")) : null,
26681
+ dragActive ? React.createElement("span", { className: "we-picker__hint" }, weT("仅支持 JPG / PNG / MP4")) : null,
26682
+ );
26683
+ }
26684
+
26545
26685
  // 筛选条(pre.51):只有 [缓存][子标签][来源] 三个下拉 + 搜索 + 视图切换。
26546
26686
  // 分级 / 类型两档已按用户口径删除(「侧栏快捷键壁纸筛选条改成三个下拉」)。
26547
26687
  // 取值与处理器全部经 `filters` 入参进来 —— 本函数是纯渲染器,不读外层 state,
@@ -26550,6 +26690,9 @@ window.__ModuleLoader__.load({
26550
26690
  const {
26551
26691
  cacheFilter, subtagFilter, subtagOptions, sourceFilter,
26552
26692
  onCacheFilterChange, onSubtagFilterChange,
26693
+ // 本地上传入口的 UI 态与动作也随 `filters` 这一份渲染 ctx 进来(不新开第 5 个形参:
26694
+ // 该签名被 verify-panel-interactions 的既有判据按字面锚定)。
26695
+ upload,
26553
26696
  } = filters || {};
26554
26697
  return React.createElement("div", { className: "we-qp__viewbar" },
26555
26698
  // 第一行:搜索 + 列表/卡片切换。搜索不再 basis:100% 独占整行 —— 窄侧栏里
@@ -26562,6 +26705,12 @@ window.__ModuleLoader__.load({
26562
26705
  "aria-label": weT("搜索壁纸标题"),
26563
26706
  onInput: (e) => { setTransient("qpSearch", e.target.value); emit(); },
26564
26707
  }),
26708
+ // 本地上传入口:搜索框右边(用户点名要的位置)。窄侧栏里按钮只显示图标,
26709
+ // 完整文案在 title / aria-label 里 —— 见 styles-quick.js 的 420px 断点。
26710
+ React.createElement(QpUploadControl, {
26711
+ busy: Boolean(upload && upload.busy),
26712
+ onFiles: upload && upload.onFiles,
26713
+ }),
26565
26714
  // 列表 / 卡片:标签式切换(滑动胶囊做激活指示、无分段底 —— 样式见
26566
26715
  // .we-qp__viewtabs),偏好记 localStorage(QP_VIEW_KEY),两个壳共用一份。
26567
26716
  // 语义仍是开关(role=group + aria-pressed),只是外观走标签形态。
@@ -26591,6 +26740,8 @@ window.__ModuleLoader__.load({
26591
26740
  }, weT("卡片")),
26592
26741
  ),
26593
26742
  ),
26743
+ // 上传状态行:搜索行下方(进度 / 错误 / 重复提示 / 拖拽提示)。
26744
+ qpRenderUploadStatus(sel, upload && upload.progress, Boolean(upload && upload.dragActive)),
26594
26745
  // ① 缓存状态:全部 / 已缓存 / 未缓存(pre.51 新)。
26595
26746
  React.createElement("select", {
26596
26747
  className: "we-picker__select we-qp__filter we-qp__cache",
@@ -26672,7 +26823,17 @@ window.__ModuleLoader__.load({
26672
26823
  // sourceFilter + 两个 handler)。**不要在函数体里直接读外层 state** —— 那是
26673
26824
  // "cacheFilter is not defined" 的来源,也是上次改签名时定义/调用一起被替换的原因。
26674
26825
  function qpRenderLibrarySection(sel, view, filters, listRef, rows, cardsView, vTopH, vBtmH, q, switchView) {
26675
- return React.createElement("div", { className: "we-qp__section we-qp__library" },
26826
+ // 拖拽上传落在**整块列表区**(不是只落在 `.we-qp__list` 那条窄容器上):列表为空 /
26827
+ // 只有一行空态文案时,整块区域仍可接住拖进来的文件。落点高亮由 --drop 修饰类画。
26828
+ // 上传的 UI 态同样经 `filters.upload` 进来(父组件的 state 只在那里装配一次)。
26829
+ const upload = filters && filters.upload;
26830
+ const dragActive = Boolean(upload && upload.dragActive);
26831
+ return React.createElement("div", {
26832
+ className: "we-qp__section we-qp__library" + (dragActive ? " we-qp__library--drop" : ""),
26833
+ onDragOver: upload && upload.onDragOver,
26834
+ onDragLeave: upload && upload.onDragLeave,
26835
+ onDrop: upload && upload.onDrop,
26836
+ },
26676
26837
  !sel.loaded
26677
26838
  ? React.createElement("span", { className: "we-picker__hint" }, weT("扫描 Wallpaper Engine…"))
26678
26839
  : sel.inventory.error
@@ -26785,6 +26946,82 @@ window.__ModuleLoader__.load({
26785
26946
  // 虚拟滚动的测量锚点:挂在下面列表容器上(qpVirtWindow 的 effect 只在浏览器跑,
26786
26947
  // 渲染期只借 useRef 的壳)。hook 顺序必须稳定 —— 排在 view / qpTab 两个 useState 之后。
26787
26948
  const listRef = React.useRef(null);
26949
+ // ── 侧栏本地上传(pre.70)──────────────────────────────────────────────
26950
+ // 三个 hook 刻意排在**所有既有 useState / useRef 之后**:现有守卫(verify-scene-live)
26951
+ // 用一条队列按序喂 useState,插在前面会把 fontOpen / glassDetailOpen 那几档的值顶错位。
26952
+ const [uploadState, setUploadState] = React.useState({ busy: false, done: 0, total: 0 });
26953
+ const [uploadDragActive, setUploadDragActive] = React.useState(false);
26954
+ // 防连点:state 更新是异步的,同一帧里连按两次会各起一条串行链。
26955
+ const uploadBusyRef = React.useRef(false);
26956
+ const runQpUpload = async (filesIn) => {
26957
+ if (uploadBusyRef.current || sel.uploading) return;
26958
+ const files = Array.from(filesIn || []).filter((f) => f && typeof f.name === "string" && f.name);
26959
+ if (!files.length) return;
26960
+ uploadBusyRef.current = true;
26961
+ setUploadState({ busy: true, done: 0, total: files.length });
26962
+ try {
26963
+ await qpUploadFilesSequential(files, {
26964
+ // 复用设置页同一条上传函数:它自己会 applySelection(选中刚上传的那张),
26965
+ // 用 transient 报错 / 重复提示;这里只按"结束后有没有 uploadError"判成功。
26966
+ uploadOne: async (file) => {
26967
+ await uploadWallpaperFile(file);
26968
+ return { ok: !sel.uploadError, duplicate: Boolean(sel.uploadNote) };
26969
+ },
26970
+ onProgress: (p) => setUploadState(p),
26971
+ onSuccess: () => {
26972
+ // 成功后立刻把来源切到「本机」:否则当前若是「站点」筛选,刚上传的那张
26973
+ // 只被 applySelection 选中、列表里却看不见(用户会以为上传丢了)。
26974
+ if (sel.sourceFilter !== "local") {
26975
+ setSetting("sourceFilter", "local");
26976
+ emit();
26977
+ }
26978
+ },
26979
+ });
26980
+ } catch (err) {
26981
+ // 上传函数内部的失败已经转成 uploadError;这里兜的是编排层意外(绝不让面板卡在忙碌态)。
26982
+ setTransient("uploadError", weT("上传失败:{error}", {
26983
+ error: weT(err && err.message ? err.message : err),
26984
+ }));
26985
+ emit();
26986
+ } finally {
26987
+ uploadBusyRef.current = false;
26988
+ setUploadState((prev) => ({ busy: false, done: prev.total, total: prev.total }));
26989
+ }
26990
+ };
26991
+ const qpUploadDragOver = (e) => {
26992
+ const dt = e.dataTransfer;
26993
+ if (!dt) return;
26994
+ const types = dt.types;
26995
+ const hasFiles = types && (typeof types.includes === "function"
26996
+ ? types.includes("Files")
26997
+ : Array.prototype.indexOf.call(types, "Files") >= 0);
26998
+ if (!hasFiles) return;
26999
+ // 不 preventDefault 浏览器就会用默认行为(导航 / 打开文件)接管 drop。
27000
+ e.preventDefault();
27001
+ dt.dropEffect = "copy";
27002
+ if (!uploadDragActive) setUploadDragActive(true);
27003
+ };
27004
+ const qpUploadDragLeave = (e) => {
27005
+ // 在子节点之间移动也会触发 dragleave:只有真正离开整块列表区才撤掉高亮。
27006
+ if (e.currentTarget && e.relatedTarget && e.currentTarget.contains(e.relatedTarget)) return;
27007
+ setUploadDragActive(false);
27008
+ };
27009
+ const qpUploadDrop = (e) => {
27010
+ e.preventDefault();
27011
+ setUploadDragActive(false);
27012
+ const files = qpDroppedFiles(e.dataTransfer);
27013
+ if (files.length) runQpUpload(files);
27014
+ };
27015
+ const qpUpload = {
27016
+ busy: uploadState.busy || Boolean(sel.uploading),
27017
+ progress: uploadState,
27018
+ dragActive: uploadDragActive,
27019
+ onFiles: runQpUpload,
27020
+ onDragOver: qpUploadDragOver,
27021
+ onDragLeave: qpUploadDragLeave,
27022
+ onDrop: qpUploadDrop,
27023
+ };
27024
+
26788
27025
 
26789
27026
  const list = sel.inventory.wallpapers;
26790
27027
  const current = list.find((w) => w.id === sel.id) || null;
@@ -26926,6 +27163,8 @@ window.__ModuleLoader__.load({
26926
27163
  // 两个 handler 直接从同一 bundle 作用域取(client.js 里的
26927
27164
  // onCacheFilterChange / onSubtagFilterChange:写持久化键 + emit)。
26928
27165
  onCacheFilterChange, onSubtagFilterChange,
27166
+ // 本地上传的进度 / 拖拽态 / 动作:渲染器只读这份 ctx。
27167
+ upload: qpUpload,
26929
27168
  }, listRef, rows, cardsView, vTopH, vBtmH, q, switchView),
26930
27169
  // 声音(与播放页那份同源:同一份渲染器、同一状态)。包一层 .we-qp__section
26931
27170
  // 只为保留这一节的分隔线与间距(渲染器自己那份 section 是给设置页排版的)。
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "dsh-folia",
3
3
  "displayName": "Folia · 壁纸引擎与桌宠",
4
- "version": "4.26.0-pre.69",
4
+ "version": "4.26.0-pre.70",
5
5
  "description": "DSH 壁纸引擎:本机 WE 壁纸实时渲染,视频/网页/开机动画/桌宠皮肤,一键拉取在线素材。",
6
6
  "type": "module",
7
7
  "engines": {