MCPcopy
hub / github.com/marktext/marktext / init

Function init

packages/muya/src/ui/baseFloat/index.ts:45–74  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

43 }
44
45 init() {
46 const floatBox = document.createElement('div');
47 const container = document.createElement('div');
48 // Use to remember which float container is shown.
49 container.classList.add(this.name);
50 container.classList.add('mu-float-container');
51 floatBox.classList.add('mu-float-wrapper');
52
53 floatBox.appendChild(container);
54 document.body.appendChild(floatBox);
55
56 this.floatBox = floatBox;
57 this.container = container;
58
59 // Since the size of the container is not fixed and changes according to the change of content,
60 // the floatBox needs to set the size according to the container size
61 const resizeObserver = (this._resizeObserver = new ResizeObserver(() => {
62 // Use requestAnimationFrame to avoid "ResizeObserver loop completed" warning
63 requestAnimationFrame(() => {
64 const { offsetWidth, offsetHeight } = container;
65
66 Object.assign(floatBox.style, {
67 width: `${offsetWidth}px`,
68 height: `${offsetHeight}px`,
69 });
70 });
71 }));
72
73 resizeObserver.observe(container);
74 }
75
76 listen() {
77 const { eventCenter, domNode } = this.muya;

Callers 2

snabbdom.tsFile · 0.50
snabbdom.jsFile · 0.50

Calls 2

appendChildMethod · 0.80
addMethod · 0.45

Tested by

no test coverage detected