Fix Bless India asset base: resolveAssetsBase(profileConfig) not runtime deriveTreeBase

deriveTreeBase() called inside build() returned '' (document.currentScript is
null by then), so the India boundaries loaded from /assets (the host's HTML
page) and the poster failed with 'Unexpected token <'. Use the house helper
resolveAssetsBase(profileConfig): the shells pass an absolute assetsBase, and
the standalone leaf falls back to the bundle's own tree root (import.meta.url,
captured at load). Verified: the leaf draws the 3-sheet poster, 0 errors.
This commit is contained in:
Doxa Maps 2026-10-02 16:52:55 +00:00
parent b8473733a9
commit 824a7ef2c2

View file

@ -73,12 +73,25 @@ import PanelSheets from '@map/components/poster/PanelSheets.vue'
import { POSTER_LADDER } from '@map/constants/posterSizes.js'
import { createPeopleGroupRecords } from '@map/lists/peopleGroupRecords.js'
import { getApiBaseUrl } from '@map/api/apiBaseUrl.js'
import { deriveTreeBase } from '@map/utils/embedScript.js'
import { resolveAssetsBase } from '@map/utils/embedBase.js'
import { ISO3_NAME } from '@map/data/iso3-name.js'
import seriesJson from '@map/scripts/posters/series.json'
import { generatePoster } from './src/generate.js'
import { loadBoundaries } from './src/boundaries.js'
// The host (a shell, or a plain embed) passes profile-config; the shells (Posterverse, the Research
// Gallery) write an ABSOLUTE assetsBase + treeBase into it. resolveAssetsBase reads that, else falls
// to the bundle's own tree root (import.meta.url, captured at script load — NOT a runtime
// deriveTreeBase(), which returns '' once document.currentScript is gone, the bug that made the
// boundaries load from /assets, the host's HTML page). Rule: load assets from the assets base.
const props = defineProps({ profileConfig: { type: [String, Object], default: '' } })
const parsedConfig = (() => {
const c = props.profileConfig
if (!c) return {}
if (typeof c === 'object') return c
try { return JSON.parse(c) } catch { return {} }
})()
const SHEETS = POSTER_LADDER['60x96'].sheets // { sheetW:60, sheetH:36, count:3, direction, joinIn:6 }
const seriesDef = (seriesJson && seriesJson.country) || {}
@ -93,17 +106,13 @@ const stats = ref(null)
const realPhotos = ref(151)
let blobUrl = ''
function treeBase() {
try { return (deriveTreeBase() || '').replace(/\/$/, '') } catch { return '' }
}
async function build() {
busy.value = true; error.value = ''
try {
const recordsFor = createPeopleGroupRecords({ apiBase: () => getApiBaseUrl(), lang: () => 'en' })
const [records, boundaries] = await Promise.all([
recordsFor({ type: 'country', values: ['IND'] }),
loadBoundaries(`${treeBase()}/assets`),
loadBoundaries(resolveAssetsBase(parsedConfig)),
])
const { html, svg, stats: s, count } = await generatePoster({
records, ...boundaries, seriesDef, iso3Name: ISO3_NAME, format: '60x96c4b',