diff --git a/src/models/configuration.js b/src/models/configuration.js index 27f370c..1ba5950 100644 --- a/src/models/configuration.js +++ b/src/models/configuration.js @@ -99,3 +99,18 @@ export const schema = z.object({ }); /** @typedef {z.infer} Configuration */ + +export const defaultConfig = { + rotatePage: false, + paperRotation90: false, + cropMarks: false, + cutMarks: false, + pdfEdgeMarks: false, + mainForeEdgePaddingPt: 0, + bindingEdgePaddingPt: 0, + topEdgePaddingPt: 0, + bottomEdgePaddingPt: 0, + sigLength: 4, // Specific to standard + foreEdgePaddingPt: 0, // specific to wacky small + flyleafs: 1, +}; diff --git a/src/utils/formUtils.js b/src/utils/formUtils.js index a477b5b..dcdbbb4 100644 --- a/src/utils/formUtils.js +++ b/src/utils/formUtils.js @@ -2,7 +2,7 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at https://mozilla.org/MPL/2.0/. -import { schema } from '../models/configuration'; +import { defaultConfig, schema } from '../models/configuration'; import { clearLocalSettings, getLocalSettings, setLocalSettings } from './localStorageUtils'; import { renderFormFromSettings, renderInfoBox, renderPageCount, renderWacky } from './renderUtils'; import { clearUrlParams, setUrlParams, toUrlParams, updateWindowLocation } from './uri'; @@ -47,7 +47,8 @@ const fromFormToConfiguration = (form) => * @param { import("../models/configuration").Configuration } configuration The configuration to set */ const setConfigurationToUrl = (configuration) => { - updateWindowLocation(setUrlParams(window.location.href, configuration)); + const cleanedConfig = removeDefaults(configuration); + updateWindowLocation(setUrlParams(window.location.href, cleanedConfig)); }; /** @@ -108,3 +109,19 @@ export const resetForm = () => { updateWindowLocation(clearUrlParams(window.location.href)); return loadForm(); }; + +/** + * Returns a version of the configuration with any items set to default values removed + * to keep url strings a little cleaner. + * @param { import("../models/configuration").Configuration } configuration The form to save + * @returns { import("../models/configuration").Configuration } The updated configuration set + */ +function removeDefaults(configuration) { + const cleaned = {}; + Object.keys(configuration).forEach((key) => { + if (defaultConfig[key] != configuration[key]) { + cleaned[key] = configuration[key]; + } + }); + return cleaned; +}