MCPcopy
hub / github.com/shuding/cobe / createAnchorManager

Function createAnchorManager

src/anchor.js:9–111  ·  view source on GitHub ↗
(wrapper)

Source from the content-addressed store, hash-verified

7 * @returns {{ m: Function, a: Function, r: Function }}
8 */
9export 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]

Callers 1

index.jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…