How page-wide defaults are set, where they come from, and how they combine with per-job options.
Three layers, merged shallowly in this order:
DEFAULTS < Printcraft.defaults < per-call options
DEFAULTS is the library baseline. Printcraft.defaults is the house style for
a page, whatever set it. Per-call options always win.
Printcraft.applyConfig({ footerText: 'internal', pageMargin: '18mm' });
Printcraft.print('#a'); // footer: "internal"
Printcraft.print({ target: '#b', footerText: '' }); // footer: noneRead automatically at boot, before any trigger fires:
<script type="application/json" data-printcraft-config>
{
"documentTitle": "ACME invoices",
"pageMargin": "18mm",
"stripDarkMode": true,
"excludeSelectorList": [".ads", "nav", "footer"]
}
</script><script src="printcraft.umd.js" data-config="/printcraft.config.json"></script>The fetch is asynchronous, so a job triggered in the first few milliseconds of page life may run before the file lands. Use the inline block when the defaults must apply to the very first job.
A sample file ships at demo/printcraft.config.json.
Printcraft.applyConfig({ watermarkText: 'DRAFT' }); // merge an object
await Printcraft.loadConfig('/printcraft.config.json'); // merge a fetched file
Printcraft.defaults; // read the live object
Printcraft.defaults = {}; // reset entirelyBoth emit config:loaded on the global bus with a source of 'object' or the
URL, which is useful for confirming that a config actually applied:
Printcraft.on('config:loaded', ({ source, config }) => {
console.log('config from', source, config);
});Anything a config file can set, a trigger can set for one job. See
Surfaces for the attribute form and its type coercion. Content
annotations (data-printcraft-exclude, -break-before, -redact, -note, …)
are honoured regardless of how the job was described, so they are the right place
for rules that belong to the content rather than to a particular job.
<script src="printcraft.umd.js" data-auto-init="false"></script>Nothing is installed until you ask:
const teardown = Printcraft.initDeclarative(); // delegated triggers
teardown(); // and remove them againThree ways to turn on per-stage timing logs, any of which is enough:
Printcraft.debug(true); // api
localStorage.setItem('printcraft:debug', '1'); // sticky, per origin
location.href + '?printcraft-debug'; // per page loadA single job can opt in or out regardless: { debug: true } beats the global
flag. See Devtools.