MCPcopy
hub / github.com/markmap/markmap / loadCSSItem

Function loadCSSItem

packages/markmap-common/src/loader.ts:54–84  ·  view source on GitHub ↗
(item: CSSItem)

Source from the content-addressed store, hash-verified

52}
53
54async function loadCSSItem(item: CSSItem) {
55 const url = (item.type === 'stylesheet' && item.data.href) || '';
56 item.loaded ||= cssCache[url];
57 if (!item.loaded) {
58 const deferred = defer<void>();
59 item.loaded = deferred.promise;
60 if (url) cssCache[url] = item.loaded;
61 if (item.type === 'style') {
62 document.head.append(
63 hm('style', {
64 textContent: item.data,
65 }),
66 );
67 deferred.resolve();
68 } else if (url) {
69 document.head.append(
70 hm('link', {
71 rel: 'stylesheet',
72 ...item.data,
73 }),
74 );
75 fetch(url)
76 .then((res) => {
77 if (res.ok) return res.text();
78 throw res;
79 })
80 .then(() => deferred.resolve(), deferred.reject);
81 }
82 }
83 await item.loaded;
84}
85
86export async function loadJS(items: JSItem[], context?: object): Promise<void> {
87 items.forEach((item) => {

Callers 1

loadCSSFunction · 0.85

Calls 1

deferFunction · 0.90

Tested by

no test coverage detected