{
  "version": 3,
  "sources": ["../../renderer/src/i18n.js", "../../renderer/src/i18n-page.js"],
  "sourcesContent": ["/**\n * The editor/reader catalogue (#420), with Django's names and signatures so `makemessages` finds\n * every call. Importing it has no side effects: until a page calls `usePageCatalogue()`, calls\n * answer in source English, which is what `<scrolling-story>` gets (PCB-25).\n */\n\nconst CONTEXT_SEPARATOR = '\\x04';\nconst PAGE_CATALOGUE_ID = 'ss-catalogue';\n\nlet readSource = null;\nlet cache = null;\n/** #819: the catalogue's language; source English until a page names its own. */\nlet readLanguage = () => 'en';\n\n/** Our own pages only: read `#ss-catalogue` (written by `partials/catalogue.html`) on first use. */\nexport function usePageCatalogue(doc = typeof document !== 'undefined' ? document : null) {\n    readSource = () => {\n        const el = doc ? doc.getElementById(PAGE_CATALOGUE_ID) : null;\n        if (!el || !el.textContent) return {};\n        try {\n            return JSON.parse(el.textContent) || {};\n        } catch {\n            return {};\n        }\n    };\n    cache = null;\n    readLanguage = () => {\n        const el = doc ? doc.getElementById(PAGE_CATALOGUE_ID) : null;\n        return (el && el.getAttribute('data-lang')) || 'en';\n    };\n}\n\n/** The language our own words are in: `data-lang` on `#ss-catalogue`, or English (#819). */\nexport function interfaceLanguage() {\n    return readLanguage();\n}\n\n/** #832: the languages written right to left, pinned equal to `stories/language.py` by `test_story_direction.py`. */\nconst RTL_LANGUAGES = new Set(['ar', 'fa', 'he', 'ur']);\n/** #832: the Arabic-script ones, whose joined letters `letter-spacing` breaks apart. */\nconst JOINED_LANGUAGES = new Set(['ar', 'fa', 'ur']);\n\n/** #832: `'rtl'` or `'ltr'` for a BCP 47 tag, read by its primary subtag. The one reader of which way a language runs. */\nexport function languageDirection(code) {\n    const primary = String(code || '').split('-')[0].toLowerCase();\n    return RTL_LANGUAGES.has(primary) ? 'rtl' : 'ltr';\n}\n\n/** #832: whether a language's letters join, so its words take no letter spacing. */\nexport function joinedScript(code) {\n    return JOINED_LANGUAGES.has(String(code || '').split('-')[0].toLowerCase());\n}\n\n/**\n * #819: an element of our own words inside a story in another language says the interface's.\n * `storyLanguage` empty (a document published before the field) leaves the element to inherit.\n * #832: and its direction, so the reader bar and menus stay put in a right-to-left story.\n */\nexport function markInterfaceLanguage(el, storyLanguage) {\n    if (!el || !storyLanguage) return el;\n    const ui = interfaceLanguage();\n    if (ui && ui !== storyLanguage) el.lang = ui;\n    else el.removeAttribute('lang');\n    const uiDir = languageDirection(ui);\n    if (uiDir !== languageDirection(storyLanguage)) el.dir = uiDir;\n    else el.removeAttribute('dir');\n    return el;\n}\n\n/**\n * #832: our own words drawn outside the stage (an overlay, a toast) say the interface's language and direction\n * against the page's, which on a story's page is the story's.\n */\nexport function markOwnWords(el, doc = typeof document !== 'undefined' ? document : null) {\n    return markInterfaceLanguage(el, doc?.documentElement?.lang || '');\n}\n\n/** #832: `markOwnWords` as attributes, for our own words written into a string of HTML. */\nexport function ownWordsAttrs(doc = typeof document !== 'undefined' ? document : null) {\n    if (!doc || !doc.createElement) return '';\n    const el = markOwnWords(doc.createElement('span'), doc);\n    return (el.lang ? ` lang=\"${el.lang}\"` : '') + (el.dir ? ` dir=\"${el.dir}\"` : '');\n}\n\nfunction catalogue() {\n    if (!cache) cache = readSource ? readSource() : {};\n    return cache;\n}\n\n/** Two forms until a second language brings its own plural rule (design item 2). */\nfunction pluralidx(count) {\n    return count === 1 ? 0 : 1;\n}\n\nexport function gettext(message) {\n    const value = catalogue()[message];\n    if (typeof value === 'undefined' || value === '') return withoutContext(message);\n    return typeof value === 'string' ? value : value[0];\n}\n\n/** A `pgettext_noop` key untranslated: the English, never its context. */\nfunction withoutContext(message) {\n    const at = message.indexOf(CONTEXT_SEPARATOR);\n    return at < 0 ? message : message.slice(at + 1);\n}\n\nexport function ngettext(singular, plural, count) {\n    const value = catalogue()[singular];\n    if (typeof value === 'undefined') return count === 1 ? singular : plural;\n    if (!Array.isArray(value)) return value;\n    return value[pluralidx(count)] || (count === 1 ? singular : plural);\n}\n\nexport function pgettext(context, message) {\n    return gettext(context + CONTEXT_SEPARATOR + message);\n}\n\nexport function npgettext(context, singular, plural, count) {\n    let value = ngettext(context + CONTEXT_SEPARATOR + singular, context + CONTEXT_SEPARATOR + plural, count);\n    if (value.includes(CONTEXT_SEPARATOR)) value = ngettext(singular, plural, count);\n    return value;\n}\n\n/** Marks a msgid for `makemessages` on a constant; `gettext()` translates it where it's shown. */\nexport function gettext_noop(message) {\n    return message;\n}\n\n/** `gettext_noop` with a context: `gettext()` of what it returns reads the entry with that context. */\nexport function pgettext_noop(context, message) {\n    return context + CONTEXT_SEPARATOR + message;\n}\n\n/** `named`: `%(key)s` from `obj`. Positional: `%s` from `obj`, in order, as `django.interpolate` does. */\nexport function interpolate(fmt, obj, named) {\n    if (named) {\n        return fmt.replace(/%\\(\\w+\\)s/g, (match) => String(obj[match.slice(2, -2)]));\n    }\n    return fmt.replace(/%s/g, () => String(obj.shift()));\n}\n\n/** A test that swaps `#ss-catalogue` mid-run reads it again with this. */\nexport function _resetCatalogueCache() {\n    cache = null;\n}\n", "// #420: the component never loads this catalogue into a host page.\nimport {\n    gettext,\n    gettext_noop,\n    interpolate,\n    joinedScript,\n    languageDirection,\n    ngettext,\n    npgettext,\n    pgettext,\n    pgettext_noop,\n    usePageCatalogue,\n} from './i18n.js';\n\nusePageCatalogue(document);\n\nObject.assign(window, { gettext, ngettext, pgettext, npgettext, gettext_noop, pgettext_noop, interpolate });\n/* #832: which way a story's language runs, for the editor's plain scripts. */\nwindow.ssLanguage = { languageDirection, joinedScript };\n"],
  "mappings": "MAOA,IAAMA,EAAoB,eAEtBC,EAAa,KACbC,EAAQ,KAERC,EAAe,IAAM,KAGlB,SAASC,EAAiBC,EAAM,OAAO,SAAa,IAAc,SAAW,KAAM,CACtFJ,EAAa,IAAM,CACf,IAAMK,EAAKD,EAAMA,EAAI,eAAeL,CAAiB,EAAI,KACzD,GAAI,CAACM,GAAM,CAACA,EAAG,YAAa,MAAO,CAAC,EACpC,GAAI,CACA,OAAO,KAAK,MAAMA,EAAG,WAAW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QL,CAAK,EACjBA,EAAMJ,EAAUC,CAAK,CAAC,IAAMA,IAAU,EAAIO,EAAWC,GAD1BL,CAEtC,CAEO,SAASM,EAASC,EAASR,EAAS,CACvC,OAAOD,EAAQS,EAAU,IAAoBR,CAAO,CACxD,CAEO,SAASS,EAAUD,EAASH,EAAUC,EAAQR,EAAO,CACxD,IAAIG,EAAQG,EAASI,EAAU,IAAoBH,EAAUG,EAAU,IAAoBF,EAAQR,CAAK,EACxG,OAAIG,EAAM,SAAS,GAAiB,IAAGA,EAAQG,EAASC,EAAUC,EAAQR,CAAK,GACxEG,CACX,CAGO,SAASS,EAAaV,EAAS,CAClC,OAAOA,CACX,CAGO,SAASW,EAAcH,EAASR,EAAS,CAC5C,OAAOQ,EAAU,IAAoBR,CACzC,CAGO,SAASY,EAAYC,EAAKC,EAAKC,EAAO,CACzC,OAAIA,EACOF,EAAI,QAAQ,aAAeG,GAAU,OAAOF,EAAIE,EAAM,MAAM,EAAG,EAAE,CAAC,CAAC,CAAC,EAExEH,EAAI,QAAQ,MAAO,IAAM,OAAOC,EAAI,MAAM,CAAC,CAAC,CACvD,CC7HAG,EAAiB,QAAQ,EAEzB,OAAO,OAAO,OAAQ,CAAE,QAAAC,EAAS,SAAAC,EAAU,SAAAC,EAAU,UAAAC,EAAW,aAAAC,EAAc,cAAAC,EAAe,YAAAC,CAAY,CAAC,EAE1G,OAAO,WAAa,CAAE,kBAAAC,EAAmB,aAAAC,CAAa",
  "names": ["PAGE_CATALOGUE_ID", "readSource", "cache", "readLanguage", "usePageCatalogue", "doc", "el", "RTL_LANGUAGES", "JOINED_LANGUAGES", "languageDirection", "code", "primary", "joinedScript", "catalogue", "cache", "readSource", "pluralidx", "count", "gettext", "message", "value", "withoutContext", "at", "ngettext", "singular", "plural", "pgettext", "context", "npgettext", "gettext_noop", "pgettext_noop", "interpolate", "fmt", "obj", "named", "match", "usePageCatalogue", "gettext", "ngettext", "pgettext", "npgettext", "gettext_noop", "pgettext_noop", "interpolate", "languageDirection", "joinedScript"]
}
