+
設定
+
+
+
+
+
+
+
図の設定を JSON ファイルに保存し、あとで読み込めます。データは含みません。設定はこのブラウザにも控えておき、次に開いたときに戻します。
+
diff --git a/js/bridge.js b/js/bridge.js
index 9a48f8f..80861e1 100644
--- a/js/bridge.js
+++ b/js/bridge.js
@@ -5,14 +5,15 @@
// - Python の起動前に選んだファイル・変えた設定は保持され、起動後に最新の内容で1回読込・描画する。
// - Pythonコードタブのモード(code-state.js): sync は GUI の設定から生成したコードで描く。edit は利用者が編集したコードを
// 「実行」したときだけ描き、GUI の変更では再描画しない(読込は行うが自動実行しない)。
-import { subscribe, toJson, getSettings, setFileSheet, setPath, updateSeries } from "./state.js";
+import { subscribe, toJson, getSettings, replaceSettings, setFileSheet, setPath, updateComputed, updateSeries } from "./state.js";
import { addStickyWarning, removeStickyWarning, setStatus, warningTexts } from "./ui/notify.js";
import { clearPlot, showPlot } from "./ui/plotView.js";
import { showCodeOutput } from "./ui/codeOutput.js";
import { getGeneratedCode, getGeneratedGeneration, isEditMode, setCodeMode, setCodeStale, setGeneratedCode } from "./code-state.js";
import { applySkipRows, clearPreview, showPreview } from "./ui/dataPreview.js";
import { releaseComputedSources } from "./computed-refs.js";
-import { dropSourceColumns, reconcileColumns, refreshSources, setSourceColumns } from "./ui/series.js";
+import { clearColumnSeeds, dropSourceColumns, fileColumnCount, reconcileColumns, refreshSources, seedColumnCount, setSourceColumns } from "./ui/series.js";
+import { clearedColumnsPatch, mapPositionalSources } from "./settings-io.js";
import { encodingDisplayName, showEncoding, showFileName, showPastedSave } from "./ui/fileInfo.js";
import { showSheets } from "./ui/loadSection.js";
import { renderFileList, renderPreviewSource } from "./ui/fileList.js";
@@ -31,6 +32,7 @@ const LATIN_LOADING_MESSAGE = "欧文フォントを取得中…";
const LATIN_NAMES = { arimo: "Arimo", tinos: "Tinos" };
const latinFailedMessage = (kind) => `欧文フォント ${LATIN_NAMES[kind]} を取得できなかったため、標準のフォントで描画しています。`;
const SCRIPT_REFRESH_DELAY_MS = 250;
+const SETTINGS_LOADED_MESSAGE = "設定を読み込みました。ファイルを読み込むと、この設定で描きます。";
const root = document.documentElement;
let api = null; // window.mplgui(Python 側が登録)
@@ -66,6 +68,7 @@ const latinTasks = new Map(); // 欧文フォントの種類 → {state: loading
let scriptTimer = null; // 保存設定の変更に伴う、コードだけの更新(画像は変えない)
let scriptRefreshAfterRender = false;
let scriptRefreshFailed = false;
+let pendingColumnCounts = []; // R1: ファイル未読込のまま読み込んだ設定の、保存時のファイルの列数(位置ごと)。最初にファイルを選んだときに id へ付ける
let lastRenderStatus = null; // 直近の描画成功のステータス(コード更新のエラーから復帰したときに戻す)
// data-data-state: 読込中が1つでもあれば loading、なければ(一覧に)失敗が1つでもあれば error、すべて成功なら ready、ファイルなしは none。
@@ -523,6 +526,24 @@ const resetToInitialState = () => {
setStatus("");
};
+// 一覧に無いファイル id を指すデータ元(読み込んだ設定の dN が、選んだファイルの数を超えたとき)は、データ1に戻す(R1)
+const resetDanglingSources = (ids) => {
+ const known = new Set(ids);
+ const dangling = (source) => source !== "" && !known.has(source);
+ const label = (source) => (/^d\d+$/.test(source) ? `データ${Number(source.slice(1))}` : "データ元");
+ getSettings().series.forEach((s, i) => {
+ if (!dangling(s.source)) return;
+ addNote(`系列${i + 1}: 設定の${label(s.source)}に当たるファイルが無いため、データ元をデータ1に戻し、列を自動に戻しました。`);
+ updateSeries(s.id, clearedColumnsPatch(s), "reconcile");
+ if (i === 0 && getSettings().plot.xColumn) setPath("plot.xColumn", "", "reconcile");
+ });
+ getSettings().computed.forEach((c, i) => {
+ if (!dangling(c.source)) return;
+ addNote(`計算した列${i + 1}: 設定の${label(c.source)}に当たるファイルが無いため、データ元を先頭のファイルに戻しました。`);
+ updateComputed(c.id, { source: "" }, "reconcile");
+ });
+};
+
// 読込が一通り終わったとき(待っている読込が無いとき)の後処理: 列の選択肢・表示の更新、描画または失敗の報告
const finalizeLoad = ({ counted = true } = {}) => {
const list = files();
@@ -531,6 +552,7 @@ const finalizeLoad = ({ counted = true } = {}) => {
if (src && src.state === "ready") setSourceColumns(f.id, src.result.columns);
}
dropSourceColumns(list.map((f) => f.id));
+ resetDanglingSources(list.map((f) => f.id));
reconcileColumns();
updateFilesView();
refreshDataState();
@@ -662,6 +684,7 @@ export const selectFiles = (fileList, options = {}) => {
const mode = options.mode === "add" ? "add" : "replace";
const pasted = options.pasted === true;
const nextNotes = Array.isArray(options.notes) ? [...options.notes] : [];
+ const wasEmpty = files().length === 0; // 設定だけ先に読み込んでいたとき(R1)、データ元の dN は新しい一覧の id と位置で対応する
let entries = mode === "add" ? files().map((f) => ({ ...f })) : [];
const accepted = [];
let skipped = 0;
@@ -694,7 +717,9 @@ export const selectFiles = (fileList, options = {}) => {
sources.clear();
pendingLoad.clear();
if (api) callPython("clearSources");
- for (const s of getSettings().series) if (s.source !== "") updateSeries(s.id, { source: "" }, "reconcile");
+ for (const s of getSettings().series) {
+ if (s.source !== "" && !(wasEmpty && entries.some((e) => e.id === s.source))) updateSeries(s.id, { source: "" }, "reconcile");
+ }
nextNotes.push(...releaseComputedSources((src) => src !== "" && !entries.some((e) => e.id === src))); // 無くなった id をデータ元にしていた計算した列
previewId = null;
}
@@ -702,6 +727,11 @@ export const selectFiles = (fileList, options = {}) => {
const old = sources.get(id);
sources.set(id, { id, file, bytes: null, pasted, state: "loading", result: old ? old.result : null, error: "", errorInfo: null });
}
+ if (wasEmpty) {
+ // 設定ファイルの保存時の列数を、新しいファイルの id に付ける(計算した列の番号の付け替えの基準)
+ entries.forEach((e, k) => seedColumnCount(e.id, pendingColumnCounts[k]));
+ pendingColumnCounts = [];
+ }
notes = nextNotes;
setPath("load.files", entries, "reconcile"); // 再読込は下で予約する
updateFilesView();
@@ -886,8 +916,47 @@ const handlePythonReady = () => {
scheduleLoad(LOAD_DELAY_MS.file, "all"); // 起動前に選ばれたファイルがあれば、最新の設定で読み込んで1回描画する
};
+// 設定の保存用: 読み込み中のファイルごとの名前・シート・ファイルの列数(不明は null)と、未読込のまま持っている保存時の列数
+export const getFilesInfo = () => files().map((f) => ({ name: f.name, sheet: f.sheet, columns: fileColumnCount(f.id) ?? null }));
+export const getPendingColumnCounts = () => pendingColumnCounts.slice();
+
+// 読み込んだ設定(settings-io.js の parseSettingsFile の結果)を、今のデータに合わせて state に入れ替える(R1)。
+// データ元 dN は、ファイルを読み込んでいれば今の N 番目のファイルに付け替え(無ければデータ1に戻して注意を出す)、
+// 読み込んでいなければ dN のまま残す。読込中のファイル一覧(load.files)は変えない。
+export const applyParsedSettings = (parsed) => {
+ const list = files();
+ const { settings: mapped, notes: mapNotes } = mapPositionalSources(parsed.settings, list.map((f) => f.id));
+ mapped.load.files = list.map((f) => ({ ...f }));
+ // 計算した列の番号は、保存したときのファイルの列数が基準。読み直したあとの列数との差で付け替える
+ clearColumnSeeds();
+ if (list.length > 0) {
+ list.forEach((f, i) => seedColumnCount(f.id, parsed.files[i] ? parsed.files[i].columns : null));
+ pendingColumnCounts = [];
+ } else {
+ pendingColumnCounts = parsed.files.map((f) => f.columns);
+ }
+ for (const note of mapNotes) addNote(note);
+ replaceSettings(mapped);
+};
+
+// 設定をまるごと入れ替えたとき: 読込設定が変わるので、ファイルがあれば全部を読み直す(そのあと今までどおり描く)
+const onSettingsReplaced = () => {
+ startLatinFont(selectedLatin()); // 欧文フォントを選んでいれば取得する(取得済みなら何もしない)
+ refreshLatinState();
+ if (files().length > 0) {
+ scheduleLoad(LOAD_DELAY_MS.file, "all");
+ return;
+ }
+ if (isEditMode()) setStatus(EDIT_MODE_MESSAGE, "warning");
+ else setStatus(SETTINGS_LOADED_MESSAGE, "ok");
+};
+
// 設定の変更を、読込・再描画・表示更新・無視のどれにするか振り分ける
const routeChange = (_settings, change) => {
+ if (change.kind === "settings-replaced") {
+ onSettingsReplaced();
+ return;
+ }
if (change.origin !== "user") return;
const path = change.kind === "path" ? change.path : "series";
if (path === "plot.skipRows") applySkipRows(getSettings().plot.skipRows); // 表の灰色表示は Python を呼ばず即時更新
diff --git a/js/main.js b/js/main.js
index 35afae2..f1a7e07 100644
--- a/js/main.js
+++ b/js/main.js
@@ -8,15 +8,16 @@ import { applyStateToForm, bindForms } from "./ui/forms.js";
import { bindSaveFormatEvents, syncSaveFormatOptions } from "./ui/saveFormat.js";
import { bindDropPaste } from "./ui/dropPaste.js";
import { bindLoadSection } from "./ui/loadSection.js";
-import { bindSaveSection } from "./ui/saveSection.js";
-import { bindDateFormat } from "./ui/dateFormat.js";
+import { bindSaveSection, syncSaveDpiView } from "./ui/saveSection.js";
+import { bindDateFormat, syncDateFormatView } from "./ui/dateFormat.js";
import { bindClipboard } from "./ui/clipboard.js";
import { addVisibilityHook, bindSeriesEvents, refreshSources, renderSeriesList, syncMarkerSizeDisplay, syncVisibility } from "./ui/series.js";
import { bindAnnotations, renderAnnotationList, syncAnnotations } from "./ui/annotations.js";
import { bindComputed, renderComputedList, syncComputed } from "./ui/computed.js";
import { bindFits, renderFitList, syncFits } from "./ui/fits.js";
import { bindPanels, syncPanels } from "./ui/panels.js";
-import { bindStyleSection } from "./ui/styleSection.js";
+import { bindStyleSection, syncStyleView } from "./ui/styleSection.js";
+import { bindSettingsSection, restoreLastSettings } from "./ui/settingsSection.js";
import { initPanelSections } from "./ui/panelSections.js";
import { bindTabs } from "./ui/tabs.js";
@@ -58,9 +59,28 @@ bindCodeTab();
bindColorPanelOutsideClick();
bindStyleSection();
+// 設定をまるごと入れ替えたとき(設定ファイルの読込・初期設定に戻す・前回の設定の復元): 画面を state から全部描き直す。
+// 入力欄、系列・注釈・近似曲線・計算した列のカード、図の単位・パレット・DPI・日時の書式、表示の出し分け
+const redrawAll = () => {
+ applyStateToForm();
+ renderSeriesList();
+ renderAnnotationList();
+ renderFitList();
+ renderComputedList();
+ refreshSources();
+ syncSaveFormatOptions();
+ syncStyleView();
+ syncSaveDpiView();
+ syncDateFormatView();
+ syncVisibility(); // パネルの配置の欄も、表示の同期(syncPanels)が合わせる
+ syncMarkerSizeDisplay();
+};
+
// state の変更に応じた画面の更新(再描画・読込の予約は bridge.js が購読して行う)
subscribe((_settings, change) => {
- if (change.kind === "series-list") {
+ if (change.kind === "settings-replaced") {
+ redrawAll();
+ } else if (change.kind === "series-list") {
renderSeriesList();
} else if (change.kind === "annotation-list") {
renderAnnotationList();
@@ -80,6 +100,8 @@ subscribe((_settings, change) => {
}
});
+restoreLastSettings(); // 前回の設定があれば戻す(画面を描く前)。データは戻さない
+bindSettingsSection(); // 復元のあとで購読する(復元そのものを「変更」として控え直さない)
applyStateToForm();
refreshSources();
syncSaveFormatOptions();
diff --git a/js/settings-io.js b/js/settings-io.js
new file mode 100644
index 0000000..51e71a3
--- /dev/null
+++ b/js/settings-io.js
@@ -0,0 +1,241 @@
+// 設定の保存・読込(R1)の純粋な部分。DOM にも state にも触れない。
+// serializeSettings: 設定オブジェクト → 保存用のラッパー(データ元の id は位置の番号にそろえる)
+// parseSettingsFile: JSON 文字列 → 検査・移行・既定値での補完をした設定
+// mapPositionalSources: 位置の番号(dN)のデータ元を、今読み込んでいるファイルの id に付け替える
+// settingsFilename: 設定ファイルの名前(保存ファイル名の規則は Python の formats.build_filename と同じ)
+import { DEFAULT_ANNOTATION, DEFAULT_COMPUTED, DEFAULT_FIT, DEFAULT_SERIES, DEFAULT_SETTINGS, SCHEMA_VERSION } from "./defaults.js";
+
+export const SETTINGS_FORMAT = "matplotlib-gui-settings";
+export const MAX_SETTINGS_BYTES = 1024 * 1024; // 設定ファイルの上限(1 MB)
+
+const clone = (value) => JSON.parse(JSON.stringify(value));
+const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
+
+// 配列の要素の既定値(キーは設定のパス)
+const DEFAULT_PANEL = { title: "", xLabel: "", yLabel: "", y2Label: "" };
+const DEFAULT_FILE = { id: "", name: "", sheet: "" };
+const ARRAY_ELEMENTS = {
+ series: DEFAULT_SERIES,
+ annotations: DEFAULT_ANNOTATION,
+ fits: DEFAULT_FIT,
+ computed: DEFAULT_COMPUTED,
+ "plot.panels": DEFAULT_PANEL,
+ "load.files": DEFAULT_FILE,
+};
+const ID_PREFIX = { series: "s", annotations: "a", fits: "f", computed: "c" };
+
+// ---- 保存 ----
+
+const positionalMap = (files) => new Map(files.map((f, i) => [f.id, `d${i + 1}`]));
+
+// filesInfo: 読み込み中のファイルごとの {name, sheet, columns}(load.files と同じ並び。columns は不明なら null)
+// names: false なら、ファイル名・シート名を含めない(localStorage 用)
+export const serializeSettings = (settings, filesInfo = [], { names = true, savedAt = new Date().toISOString() } = {}) => {
+ const copy = clone(settings);
+ const map = positionalMap(copy.load.files);
+ const remap = (source) => (source === "" ? "" : map.get(source) ?? source);
+ copy.load.files = names ? copy.load.files.map((f, i) => ({ ...f, id: `d${i + 1}` })) : [];
+ for (const s of copy.series) s.source = remap(s.source);
+ for (const c of copy.computed) c.source = remap(c.source);
+ const files = (Array.isArray(filesInfo) ? filesInfo : []).map((f) => {
+ const info = f || {};
+ const columns = Number.isInteger(info.columns) && info.columns >= 0 ? info.columns : null;
+ return names ? { name: String(info.name ?? ""), sheet: String(info.sheet ?? ""), columns } : { columns };
+ });
+ return { format: SETTINGS_FORMAT, savedAt, files, settings: copy };
+};
+
+// ---- 読込 ----
+
+export class SettingsFileError extends Error {}
+
+const fail = (message) => {
+ throw new SettingsFileError(message);
+};
+
+// Python の settings.migrate_settings と同じ規則(引数は変更しない)。version が無ければ現在のバージョン扱い
+const migrate = (raw) => {
+ const out = clone(raw);
+ const version = "version" in raw ? raw.version : SCHEMA_VERSION;
+ if (version === 1) {
+ if (!isObject(out.save)) out.save = {};
+ if (!("dpi" in out.save)) out.save.dpi = 120;
+ }
+ if (version === 1 || version === 2) {
+ if (!isObject(out.load)) out.load = {};
+ if (!("parseDates" in out.load)) out.load.parseDates = false;
+ }
+ out.version = SCHEMA_VERSION;
+ return out;
+};
+
+// 既定値の形に合わせて補う。知らないキーは捨てる。形(オブジェクト・配列・値)が違うものは既定値にする。
+// 値そのものの正しさは検査しない(描画のときに Python が日本語のエラーにする)。配列は path の要素の既定値で要素ごとに補う
+const fillFrom = (def, val, path) => {
+ if (Array.isArray(def)) {
+ const element = ARRAY_ELEMENTS[path];
+ if (!Array.isArray(val) || !element) return clone(def);
+ return val.map((item) => {
+ const filled = fillFrom(element, item, `${path}[]`);
+ // id が無い要素は、既定値の id(s1 など)を借りずに空にする(あとで assignIds が新しい id を振る)
+ if ("id" in filled && !(isObject(item) && typeof item.id === "string" && item.id !== "")) filled.id = "";
+ return filled;
+ });
+ }
+ if (isObject(def)) {
+ if (!isObject(val)) return clone(def);
+ const out = {};
+ for (const key of Object.keys(def)) {
+ const childPath = path === "" ? key : `${path}.${key}`;
+ out[key] = key in val ? fillFrom(def[key], val[key], childPath) : clone(def[key]);
+ }
+ return out;
+ }
+ if (val === undefined || isObject(val) || Array.isArray(val)) return def;
+ return val;
+};
+
+const numericSuffix = (id, prefix) => {
+ const m = new RegExp(`^${prefix}(\\d+)$`).exec(typeof id === "string" ? id : "");
+ return m ? Number(m[1]) : 0;
+};
+
+export const maxIdNumber = (items, prefix) => items.reduce((max, item) => Math.max(max, numericSuffix(item && item.id, prefix)), 0);
+
+// id が「prefix + 数字」の形でない・重複している要素に、新しい id(prefix + 連番。既存の最大の番号から続ける)を振る。
+// id は画面の要素の id と HTML にそのまま入るので、形を限る(手で書いた設定ファイルの値で HTML を壊させない)。
+// 振り直した id の対応(最初に出てきた元の id → 新しい id)を返す(近似曲線の系列の参照を直すのに使う)
+const assignIds = (items, prefix) => {
+ let max = maxIdNumber(items, prefix);
+ const seen = new Set();
+ const pattern = new RegExp(`^${prefix}\\d+$`);
+ const renamed = new Map();
+ for (const item of items) {
+ if (typeof item.id !== "string" || !pattern.test(item.id) || seen.has(item.id)) {
+ const old = item.id;
+ max += 1;
+ item.id = `${prefix}${max}`;
+ if (typeof old === "string" && old !== "" && !pattern.test(old) && !renamed.has(old)) renamed.set(old, item.id);
+ }
+ seen.add(item.id);
+ }
+ return renamed;
+};
+
+const normalizeSettings = (raw) => {
+ const migrated = migrate(raw);
+ const out = {};
+ for (const key of Object.keys(DEFAULT_SETTINGS)) {
+ out[key] = key === "version" ? SCHEMA_VERSION : fillFrom(DEFAULT_SETTINGS[key], migrated[key], key);
+ }
+ if (out.series.length === 0) out.series = [clone(DEFAULT_SERIES)];
+ const renamed = {};
+ for (const [key, prefix] of Object.entries(ID_PREFIX)) renamed[key] = assignIds(out[key], prefix);
+ // 形の違う系列の id を振り直したら、その系列を指す近似曲線も新しい id にする
+ for (const f of out.fits) if (renamed.series.has(f.series)) f.series = renamed.series.get(f.series);
+ return out;
+};
+
+const looksLikeSettings = (obj) =>
+ ["plot", "axes", "load", "save"].some((k) => isObject(obj[k])) || ["series", "annotations", "fits", "computed"].some((k) => Array.isArray(obj[k]));
+
+// text: ファイルの内容。size: ファイルの大きさ(バイト。省略時は文字数)。
+// 戻り値: {settings, files: [{name, sheet, columns}]}。失敗は SettingsFileError(message は日本語。何も変えない段階の失敗)
+export const parseSettingsFile = (text, { size } = {}) => {
+ const bytes = size === undefined ? String(text).length : size;
+ if (bytes > MAX_SETTINGS_BYTES) fail("設定ファイルが大きすぎます(1 MB まで)。");
+ let data;
+ try {
+ data = JSON.parse(text);
+ } catch (_) {
+ fail("設定ファイルを読み込めませんでした: JSON の形式ではありません。");
+ }
+ const NOT_SETTINGS = "設定ファイルではありません。このアプリの「設定を保存(.json)」で保存したファイルを選んでください。";
+ if (!isObject(data)) fail(NOT_SETTINGS);
+ let raw = data;
+ let filesRaw = [];
+ if ("settings" in data || "format" in data) {
+ if (("format" in data && data.format !== SETTINGS_FORMAT) || !isObject(data.settings)) fail(NOT_SETTINGS);
+ raw = data.settings;
+ if (Array.isArray(data.files)) filesRaw = data.files;
+ }
+ if (!looksLikeSettings(raw)) fail(NOT_SETTINGS);
+ if ("version" in raw) {
+ const v = raw.version;
+ if (typeof v === "number" && Number.isInteger(v) && v > SCHEMA_VERSION) fail(`この設定ファイルは新しい版のアプリで作られたため、読み込めません(version ${v})。`);
+ if (!(typeof v === "number" && Number.isInteger(v) && v >= 1 && v <= SCHEMA_VERSION)) {
+ fail(`設定ファイルのバージョン(${typeof v === "string" ? v : JSON.stringify(v)})に対応していません。`);
+ }
+ }
+ const files = filesRaw.map((f) => {
+ const info = isObject(f) ? f : {};
+ return {
+ name: typeof info.name === "string" ? info.name : "",
+ sheet: typeof info.sheet === "string" ? info.sheet : "",
+ columns: Number.isInteger(info.columns) && info.columns >= 0 ? info.columns : null,
+ };
+ });
+ return { settings: normalizeSettings(raw), files };
+};
+
+// ---- データ元の対応(位置で合わせる)----
+
+const POSITIONAL = /^d(\d+)$/;
+
+// 系列を別のデータ元に付け替えたときに空に戻す項目(ui/series.js の onSourceChange と同じ)
+export const clearedColumnsPatch = (series) => {
+ const errorBars = clone(series.errorBars);
+ for (const dir of ["y", "x"]) Object.assign(errorBars[dir], { column: "", columnMinus: "" });
+ return { source: "", x: "", y: "", colorColumn: "", errorBars, fill: { ...series.fill, lower: "", upper: "" } };
+};
+
+// settings(コピーを返す)の系列・計算した列のデータ元 dN を、fileIds(今のファイルの id の並び)の N 番目に付け替える。
+// fileIds が空なら何もしない(読み込むまで dN のまま残す)。N 番目が無いものはデータ1に戻し、注意の文を返す
+export const mapPositionalSources = (settings, fileIds) => {
+ const out = clone(settings);
+ const notes = [];
+ if (fileIds.length === 0) return { settings: out, notes };
+ const resolve = (source) => {
+ const m = POSITIONAL.exec(source);
+ return { id: m && Number(m[1]) >= 1 && Number(m[1]) <= fileIds.length ? fileIds[Number(m[1]) - 1] : "" };
+ };
+ const missingName = (source) => (POSITIONAL.test(source) ? `データ${Number(POSITIONAL.exec(source)[1])}` : "データ元");
+ out.series.forEach((s, i) => {
+ const r = resolve(s.source);
+ if (r.id === "" && s.source !== "") {
+ const was = s.source;
+ Object.assign(s, clearedColumnsPatch(s));
+ if (i === 0) out.plot.xColumn = "";
+ notes.push(`系列${i + 1}: 設定の${missingName(was)}に当たるファイルが無いため、データ元をデータ1に戻し、列を自動に戻しました。`);
+ } else {
+ s.source = r.id;
+ }
+ });
+ out.computed.forEach((c, i) => {
+ const was = c.source;
+ c.source = resolve(was).id;
+ if (c.source === "" && was !== "") {
+ notes.push(`計算した列${i + 1}: 設定の${missingName(was)}に当たるファイルが無いため、データ元を先頭のファイルに戻しました。`);
+ }
+ });
+ return { settings: out, notes };
+};
+
+// ---- ファイル名 ----
+
+const INVALID_FILENAME_CHARS = /[\\/:*?"<>|\x00-\x1f]/g;
+// Python の str.strip() が取り除く空白(JS の trim とは少し違う)
+const PY_SPACE = "\\t\\n\\v\\f\\r\\x1c-\\x1f \\x85\\xa0\\u1680\\u2000-\\u200a\\u2028\\u2029\\u202f\\u205f\\u3000";
+const pyStrip = (s) => s.replace(new RegExp(`^[${PY_SPACE}]+|[${PY_SPACE}]+$`, "g"), "");
+
+// 保存ファイル名(入力欄の値)→ 設定ファイルの名前(