/** @jsx h */ /** @jsxFrag Fragment */ /// /// /// import { Bubble } from "./Bubble.tsx"; import { CSS } from "./app.min.css.ts"; import { Fragment, h, render, useEffect, useMemo } from "./deps/preact.tsx"; import { useBubbles } from "./useBubbles.ts"; import { useEventListener } from "./useEventListener.ts"; import { detectURL, toId } from "./utils.ts"; import { sleep } from "./sleep.ts"; import { usePromiseSettledAnytimes } from "./usePromiseSettledAnytimes.ts"; import { isLiteralStrings, isPageLink, isTitle } from "./is.ts"; import { ensureHTMLDivElement } from "./ensure.ts"; import { parseLink } from "./parseLink.ts"; import { getWatchList } from "./watchList.ts"; import { loadPage } from "./page.ts"; import { editor } from "./deps/scrapbox-std.ts"; import type { LinkType } from "./types.ts"; import type { ProjectId, Scrapbox } from "./deps/scrapbox.ts"; declare const scrapbox: Scrapbox; export { setDebugMode } from "./page.ts"; const userscriptName = "scrap-bubble"; export interface AppProps { /** hoverしてからbubbleを表示するまでのタイムラグ */ delay: number; /** 透過的に扱うprojectのリスト */ whiteList: string[]; /** watch list */ watchList: ProjectId[]; /** カスタムCSS * * URL or URL文字列の場合は、CSSファイルへのURLだとみなしてで読み込む * それ以外の場合は、インラインCSSとして {url !== "" && (url instanceof URL ? : )} {bubbles.map((bubble, index) => ( change(index + 1)} /> ))} ); }; export const mount = (init?: Partial): void => { const { delay = 500, whiteList = [], watchList = getWatchList().slice(0, 100), scrollTargets = ["link", "hashtag", "lineId", "title"], style = "", } = init ?? {}; const app = document.createElement("div"); app.dataset.userscriptName = userscriptName; const editorDiv = editor(); ensureHTMLDivElement(editorDiv, "#editor"); editorDiv.append(app); const shadowRoot = app.attachShadow({ mode: "open" }); render( , shadowRoot, ); }; const getLinkType = (element: HTMLSpanElement | HTMLAnchorElement): LinkType => isPageLink(element) ? (element.type === "link" ? "link" : "hashtag") : "title";