27 lines
988 B
TypeScript
27 lines
988 B
TypeScript
import { createApp } from './app';
|
|
import { validateAndFreezeProductionInputSnapshot } from './content/production-input-snapshot';
|
|
import type { ProductionInputs } from './content/types';
|
|
|
|
export const readProductionInputsSnapshot = (source: Document): Readonly<ProductionInputs> => {
|
|
const snapshot = source.getElementById('portfolio-inputs');
|
|
if (
|
|
snapshot === null ||
|
|
snapshot.tagName !== 'SCRIPT' ||
|
|
snapshot.getAttribute('type') !== 'application/json'
|
|
) {
|
|
throw new Error('The inert portfolio input snapshot is unavailable.');
|
|
}
|
|
|
|
const serializedInputs = snapshot.textContent;
|
|
if (serializedInputs === null || serializedInputs.length === 0) {
|
|
throw new Error('The inert portfolio input snapshot is empty.');
|
|
}
|
|
|
|
return validateAndFreezeProductionInputSnapshot(JSON.parse(serializedInputs) as unknown);
|
|
};
|
|
|
|
const appRoot = document.getElementById('app');
|
|
if (appRoot !== null) {
|
|
createApp(readProductionInputsSnapshot(document)).mount(appRoot);
|
|
}
|