Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 6x 6x 1x 1x 1x 1x 1x 1x 10x 10x 1x 1x 1x 1x 1x 1x 1x 10x 10x 1x 1x 1x 1x 1x 1x 1x 23x 84x 84x 84x 11x 11x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import { i18nTranslationStore } from '../store/translation-store.js' import { traverseUpDom } from '../algorithms/traverse-up-dom.js' const fallbackStore = i18nTranslationStore() /** @type {StoreSearchResult} */ export const noStoresFound = Object.freeze({ store: fallbackStore, }) /** @type {StoreMap} */ const map = new WeakMap() /** * Remove assigned store from element * @param {Element} element - target element */ export const unsetStoreOnElement = (element) => { map.delete(element) } /** * @param {Element} element - target element * @returns {boolean} true if there is a translation store assigned on `element`, false otherwise */ export const isStoreSetOnElement = function (element) { return map.has(element) } /** * Assigns a {@link TranslationStore} to an element, overwrites previous if already assigned * @param {Element} element - target element * @param {TranslationStore} store - store to assign */ export const setStoreFromElement = (element, store) => { map.set(element, store) } /** * Gets stores assigned and inherited from the element * @param {Element} target - target Element * @yields {StoreSearchResult} */ export const getStoresInfoFromElement = function * (target) { for (const element of traverseUpDom(target)) { const store = map.get(element) if (store) yield { store, element } } yield noStoresFound } /** * @typedef {WeakMap<Element, TranslationStore>} StoreMap */ /** * @typedef {object} StoreSearchResult * * Result of {@link getStoresInfoFromElement} * @property {TranslationStore} store - store found, or fallback store * @property {Element} [element] element where the store is assigned */ /** * @typedef {import('../store/translation-store.js').TranslationStore} TranslationStore */ |