(wrapper)
| 7 | * @returns {{ m: Function, a: Function, r: Function }} |
| 8 | */ |
| 9 | export function createAnchorManager(wrapper) { |
| 10 | const markerAnchors = {} |
| 11 | const arcAnchors = {} |
| 12 | const visibilityVars = {} |
| 13 | |
| 14 | // Create a style tag for :root CSS variables |
| 15 | const styleEl = document.createElement('style') |
| 16 | document.head.append(styleEl) |
| 17 | |
| 18 | function updateStyleTag() { |
| 19 | let vars = '' |
| 20 | for (let key in visibilityVars) { |
| 21 | vars += key + ':' + visibilityVars[key] + ';' |
| 22 | } |
| 23 | styleEl.textContent = ':root{' + vars + '}' |
| 24 | } |
| 25 | |
| 26 | function updateAnchor(anchors, key, anchorName, position) { |
| 27 | let anchor = anchors[key] |
| 28 | |
| 29 | if (!anchor) { |
| 30 | anchor = document.createElement('div') |
| 31 | anchor.style.cssText = |
| 32 | 'position:absolute;width:1px;height:1px;pointer-events:none;anchor-name:' + |
| 33 | anchorName |
| 34 | wrapper.append(anchor) |
| 35 | anchors[key] = anchor |
| 36 | } |
| 37 | |
| 38 | anchor.style.left = position.x * 100 + '%' |
| 39 | anchor.style.top = position.y * 100 + '%' |
| 40 | } |
| 41 | |
| 42 | function m(markers, project) { |
| 43 | const activeKeys = {} |
| 44 | |
| 45 | for (let marker of markers) { |
| 46 | const key = marker.id |
| 47 | if (!key) continue |
| 48 | |
| 49 | const pos = project(marker.location) |
| 50 | |
| 51 | activeKeys[key] = 1 |
| 52 | |
| 53 | updateAnchor(markerAnchors, key, `--cobe-${key}`, pos) |
| 54 | |
| 55 | if (pos.visible) { |
| 56 | visibilityVars['--cobe-visible-' + key] = 'N' |
| 57 | } else { |
| 58 | delete visibilityVars['--cobe-visible-' + key] |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | for (const key in markerAnchors) { |
| 63 | if (!activeKeys[key]) { |
| 64 | markerAnchors[key].remove() |
| 65 | delete markerAnchors[key] |
| 66 | delete visibilityVars['--cobe-visible-' + key] |
no outgoing calls
no test coverage detected
searching dependent graphs…