diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 599bee3..5e27f56 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,11 +10,5 @@ jobs: - uses: denoland/setup-deno@v1 with: deno-version: "v1.x" - - name: Check fmt - run: deno fmt --check - - name: Run lint - run: deno lint - - name: Run type check - run: deno check --remote ./**/*.ts - - name: Run test - run: deno test --allow-read --allow-write + - name: Check fmt & lint & type check & test + run: deno task check:dry diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 0000000..e187470 --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,27 @@ +# cf. https://jsr.io/@core/unknownutil/3.18.1/.github/workflows/jsr.yml +name: publish + +env: + DENO_VERSION: 1.x + +on: + push: + tags: + - '*' + +permissions: + contents: read + id-token: write # The OIDC ID token is used for authentication with JSR. + + +jobs: + publish: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Install Deno + uses: denoland/setup-deno@v1 + with: + deno-version: ${{ env.DENO_VERSION }} + - name: Publish on tag + run: deno task publish \ No newline at end of file diff --git a/.github/workflows/udd.yml b/.github/workflows/udd.yml index 7bc1850..9f787a8 100644 --- a/.github/workflows/udd.yml +++ b/.github/workflows/udd.yml @@ -1,32 +1,39 @@ -# from https://zenn.dev/kawarimidoll/articles/c68204d248c107#設定ファイル -name: update-deno-dependencies +# ported from https://github.com/jsr-core/unknownutil/blob/v3.18.1/.github/workflows/udd.yml and modified a bit +name: Update on: schedule: - cron: "0 0 * * *" + workflow_dispatch: jobs: udd: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - uses: denoland/setup-deno@v1 with: - deno-version: "v1.x" + deno-version: "1.x" - name: Update dependencies - run: > - deno run --allow-net --allow-read --allow-write=deps/ - --allow-run=deno https://deno.land/x/udd@0.8.2/main.ts deps/*.ts - --test="deno test --allow-read" - - name: Create Pull Request - uses: peter-evans/create-pull-request@v3 + run: | + deno task upgrade > ../output.txt + env: + NO_COLOR: 1 + - name: Read ../output.txt + id: log + uses: juliangruber/read-file-action@v1 with: - commit-message: ":arrow_up: update deno dependencies" - title: Update Deno Dependencies - body: > - Automated updates by [deno-udd](https://github.com/hayd/deno-udd) - and [create-pull-request](https://github.com/peter-evans/create-pull-request) - GitHub action + path: ../output.txt + - uses: peter-evans/create-pull-request@v6 + with: + commit-message: ":package: Update Deno dependencies" + title: ":package: Update Deno dependencies" + body: | + The output of `deno task update` is + + ``` + ${{ steps.log.outputs.content }} + ``` branch: update-deno-dependencies author: GitHub - delete-branch: true + delete-branch: true \ No newline at end of file diff --git a/README.md b/README.md index 98ec03e..04a6de1 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,6 @@ # scrapbox-userscript-std -UNOFFICIAL standard module for Scrapbox UserScript +[![JSR](https://jsr.io/badges/@cosense/std)](https://jsr.io/@cosense/std) +[![test](https://github.com/takker99/scrapbox-userscript-std/workflows/ci/badge.svg)](https://github.com/takker99/scrapbox-userscript-std/actions?query=workflow%3Aci) -[document](https://doc.deno.land/https://raw.githubusercontent.com/takker99/scrapbox-userscript-std/0.14.9/mod.ts) +UNOFFICIAL standard module for Scrapbox UserScript diff --git a/browser/dom/caret.ts b/browser/dom/caret.ts index 2bad859..0c09dc7 100644 --- a/browser/dom/caret.ts +++ b/browser/dom/caret.ts @@ -1,7 +1,3 @@ -/// -/// -/// - import { textInput } from "./dom.ts"; /** editor上の位置情報 */ diff --git a/browser/dom/click.ts b/browser/dom/click.ts index 8253ca6..43d3173 100644 --- a/browser/dom/click.ts +++ b/browser/dom/click.ts @@ -1,8 +1,4 @@ -/// -/// -/// - -import { sleep } from "../../sleep.ts"; +import { delay } from "@std/async/delay"; /** the options for `click()` */ export interface ClickOptions { @@ -36,7 +32,7 @@ export const click = async ( // ScrapboxのReactの処理が終わるまで少し待つ // 待ち時間は感覚で決めた - await sleep(10); + await delay(10); }; export interface HoldDownOptions extends ClickOptions { @@ -71,12 +67,12 @@ export const holdDown = async ( }; element.dispatchEvent(new TouchEvent("touchstart", mouseOptions)); element.dispatchEvent(new MouseEvent("mousedown", mouseOptions)); - await sleep(options.holding ?? 1000); + await delay(options.holding ?? 1000); element.dispatchEvent(new MouseEvent("mouseup", mouseOptions)); element.dispatchEvent(new TouchEvent("touchend", mouseOptions)); element.dispatchEvent(new MouseEvent("click", mouseOptions)); // ScrapboxのReactの処理が終わるまで少し待つ // 待ち時間は感覚で決めた - await sleep(10); + await delay(10); }; diff --git a/browser/dom/cursor.d.ts b/browser/dom/cursor.d.ts index 4518fd6..1485d88 100644 --- a/browser/dom/cursor.d.ts +++ b/browser/dom/cursor.d.ts @@ -1,10 +1,6 @@ -/// -/// -/// - -import { BaseLine, BaseStore } from "../../deps/scrapbox.ts"; -import { Position } from "./position.ts"; -import { Page } from "./page.d.ts"; +import { type BaseLine, BaseStore } from "../../deps/scrapbox.ts"; +import type { Position } from "./position.ts"; +import type { Page } from "./page.d.ts"; export interface SetPositionOptions { /** カーソルが画面外に移動したとき、カーソルが見える位置までページをスクロールするかどうか diff --git a/browser/dom/cursor.ts b/browser/dom/cursor.ts index ded767a..57edad0 100644 --- a/browser/dom/cursor.ts +++ b/browser/dom/cursor.ts @@ -1,9 +1,5 @@ -/// -/// -/// - import { takeStores } from "./stores.ts"; -import { Cursor } from "./cursor.d.ts"; +import type { Cursor } from "./cursor.d.ts"; export type { Cursor }; export const takeCursor = (): Cursor => takeStores().cursor; diff --git a/browser/dom/dom.ts b/browser/dom/dom.ts index 1190b04..4cc2d2b 100644 --- a/browser/dom/dom.ts +++ b/browser/dom/dom.ts @@ -1,6 +1,3 @@ -/// -/// -/// import { ensureHTMLAnchorElement, ensureHTMLDivElement, diff --git a/browser/dom/edit.ts b/browser/dom/edit.ts index c22a84c..b277316 100644 --- a/browser/dom/edit.ts +++ b/browser/dom/edit.ts @@ -4,7 +4,7 @@ import { getLineCount } from "./node.ts"; import { range } from "../../range.ts"; import { textInput } from "./dom.ts"; import { isArray, isNumber, isString } from "../../is.ts"; -import { sleep } from "../../sleep.ts"; +import { delay } from "@std/async/delay"; export const undo = (count = 1): void => { for (const _ of range(0, count)) { @@ -165,5 +165,5 @@ export const insertText = async (text: string): Promise => { const event = new InputEvent("input", { bubbles: true }); cursor.dispatchEvent(event); - await sleep(1); // 待ち時間は感覚で決めた + await delay(1); // 待ち時間は感覚で決めた }; diff --git a/browser/dom/ensure.ts b/browser/dom/ensure.ts index 3d8e1b7..255ad6b 100644 --- a/browser/dom/ensure.ts +++ b/browser/dom/ensure.ts @@ -1,4 +1,3 @@ -/// // These code are based on https://deno.land/x/unknownutil@v1.1.0/ensure.ts export const ensureHTMLDivElement: ( diff --git a/browser/dom/extractCodeFiles.test.ts b/browser/dom/extractCodeFiles.test.ts index a9aa551..c40df35 100644 --- a/browser/dom/extractCodeFiles.test.ts +++ b/browser/dom/extractCodeFiles.test.ts @@ -1,5 +1,5 @@ import { extractCodeFiles } from "./extractCodeFiles.ts"; -import { Line } from "../../deps/scrapbox.ts"; +import type { Line } from "../../deps/scrapbox.ts"; import { assertSnapshot } from "../../deps/testing.ts"; import sample from "./sample-lines1.json" with { type: "json" }; diff --git a/browser/dom/extractCodeFiles.ts b/browser/dom/extractCodeFiles.ts index adf2330..c425ad0 100644 --- a/browser/dom/extractCodeFiles.ts +++ b/browser/dom/extractCodeFiles.ts @@ -1,4 +1,4 @@ -import { Line } from "../../deps/scrapbox.ts"; +import type { Line } from "../../deps/scrapbox.ts"; /** 一つのソースコードを表す */ export interface CodeFile { diff --git a/browser/dom/getCachedLines.ts b/browser/dom/getCachedLines.ts index 2f2fd0a..edf7a80 100644 --- a/browser/dom/getCachedLines.ts +++ b/browser/dom/getCachedLines.ts @@ -1,4 +1,4 @@ -import { Line, Scrapbox } from "../../deps/scrapbox.ts"; +import type { Line, Scrapbox } from "../../deps/scrapbox.ts"; declare const scrapbox: Scrapbox; let isLatestData = false; diff --git a/browser/dom/isHeightViewable.ts b/browser/dom/isHeightViewable.ts index eda56a9..2dad7f5 100644 --- a/browser/dom/isHeightViewable.ts +++ b/browser/dom/isHeightViewable.ts @@ -1,7 +1,3 @@ -/// -/// -/// - export const isHeightViewable = (element: HTMLElement): boolean => { const { top, bottom } = element.getBoundingClientRect(); return top >= 0 && bottom <= globalThis.innerHeight; diff --git a/browser/dom/motion.ts b/browser/dom/motion.ts index f0f5b5e..98ffa51 100644 --- a/browser/dom/motion.ts +++ b/browser/dom/motion.ts @@ -1,7 +1,3 @@ -/// -/// -/// - import { press } from "./press.ts"; import { click, holdDown } from "./click.ts"; import { diff --git a/browser/dom/node.ts b/browser/dom/node.ts index 699a659..22e96f7 100644 --- a/browser/dom/node.ts +++ b/browser/dom/node.ts @@ -1,6 +1,3 @@ -/// -/// -/// import { isNone, isNumber, isString } from "../../is.ts"; import { ensureArray } from "../../ensure.ts"; import { getCachedLines } from "./getCachedLines.ts"; @@ -138,7 +135,7 @@ export const getInternalLink = (dom: HTMLElement): HTMLElement | undefined => { if (isNone(link)) return undefined; return link as HTMLElement; }; -export const getLink = (dom: HTMLElement) => { +export const getLink = (dom: HTMLElement): HTMLElement | undefined => { const link = dom.closest(".link, .page-link"); if (isNone(link)) return undefined; return link as HTMLElement; diff --git a/browser/dom/open.ts b/browser/dom/open.ts index d9c31da..b99f1b4 100644 --- a/browser/dom/open.ts +++ b/browser/dom/open.ts @@ -1,10 +1,6 @@ -/// -/// -/// - import { encodeTitleURI } from "../../title.ts"; import { - PageTransitionContext, + type PageTransitionContext, pushPageTransition, } from "./pushPageTransition.ts"; import type { Scrapbox } from "../../deps/scrapbox.ts"; @@ -43,7 +39,7 @@ export const open = ( project: string, title: string, options?: OpenOptions, -) => { +): void => { const url = new URL(`/${project}/${encodeTitleURI(title)}`, location.href); if (options?.body) url.search = `?body=${encodeURIComponent(options.body)}`; if (options?.id) url.hash = `#${options.id}`; @@ -88,4 +84,4 @@ export const openInTheSameTab = ( project: string, title: string, body?: string, -) => open(project, title, { newTab: false, reload: false, body }); +): void => open(project, title, { newTab: false, reload: false, body }); diff --git a/browser/dom/page.d.ts b/browser/dom/page.d.ts index 0f9e1b3..1f49b76 100644 --- a/browser/dom/page.d.ts +++ b/browser/dom/page.d.ts @@ -1,9 +1,5 @@ -/// -/// -/// - import { BaseStore } from "../../deps/scrapbox.ts"; -import { Page as PageData } from "../../deps/scrapbox-rest.ts"; +import type { Page as PageData } from "../../deps/scrapbox-rest.ts"; export interface SetPositionOptions { /** カーソルが画面外に移動したとき、カーソルが見える位置までページをスクロールするかどうか diff --git a/browser/dom/press.ts b/browser/dom/press.ts index c995874..3f9bd07 100644 --- a/browser/dom/press.ts +++ b/browser/dom/press.ts @@ -1,7 +1,3 @@ -/// -/// -/// - import { textInput } from "./dom.ts"; /** the options for `press()` */ diff --git a/browser/dom/selection.d.ts b/browser/dom/selection.d.ts index df6f530..b7d2616 100644 --- a/browser/dom/selection.d.ts +++ b/browser/dom/selection.d.ts @@ -1,9 +1,5 @@ -/// -/// -/// - -import { BaseLine, BaseStore } from "../../deps/scrapbox.ts"; -import { Position } from "./position.ts"; +import { type BaseLine, BaseStore } from "../../deps/scrapbox.ts"; +import type { Position } from "./position.ts"; export interface Range { start: Position; diff --git a/browser/dom/selection.ts b/browser/dom/selection.ts index e54a69e..ff14421 100644 --- a/browser/dom/selection.ts +++ b/browser/dom/selection.ts @@ -1,9 +1,5 @@ -/// -/// -/// - import { takeStores } from "./stores.ts"; -import { Selection } from "./selection.d.ts"; +import type { Selection } from "./selection.d.ts"; export type { Selection }; export const takeSelection = (): Selection => takeStores().selection; diff --git a/browser/dom/stores.ts b/browser/dom/stores.ts index d97ced5..c4c4603 100644 --- a/browser/dom/stores.ts +++ b/browser/dom/stores.ts @@ -1,10 +1,6 @@ -/// -/// -/// - import { textInput } from "./dom.ts"; -import { Cursor } from "./cursor.d.ts"; -import { Selection } from "./selection.d.ts"; +import type { Cursor } from "./cursor.d.ts"; +import type { Selection } from "./selection.d.ts"; export type { Cursor, Selection }; export const takeStores = (): { cursor: Cursor; selection: Selection } => { diff --git a/browser/dom/takeInternalLines.ts b/browser/dom/takeInternalLines.ts index b6ee927..666eb56 100644 --- a/browser/dom/takeInternalLines.ts +++ b/browser/dom/takeInternalLines.ts @@ -1,5 +1,5 @@ import { lines } from "./dom.ts"; -import { BaseLine } from "../../deps/scrapbox.ts"; +import type { BaseLine } from "../../deps/scrapbox.ts"; /** Scrapbox内部の本文データの参照を取得する * diff --git a/browser/dom/textInputEventListener.ts b/browser/dom/textInputEventListener.ts index 97cf536..dc2346a 100644 --- a/browser/dom/textInputEventListener.ts +++ b/browser/dom/textInputEventListener.ts @@ -1,4 +1,4 @@ -import { Scrapbox } from "../../deps/scrapbox.ts"; +import type { Scrapbox } from "../../deps/scrapbox.ts"; import { textInput } from "./dom.ts"; import { decode, encode } from "./_internal.ts"; declare const scrapbox: Scrapbox; diff --git a/browser/websocket/_codeBlock.test.ts b/browser/websocket/_codeBlock.test.ts index 64f1313..69ebd49 100644 --- a/browser/websocket/_codeBlock.test.ts +++ b/browser/websocket/_codeBlock.test.ts @@ -1,5 +1,3 @@ -/// - import { assertEquals, assertSnapshot } from "../../deps/testing.ts"; import { extractFromCodeTitle } from "./_codeBlock.ts"; diff --git a/browser/websocket/_codeBlock.ts b/browser/websocket/_codeBlock.ts index 8702123..83d5db0 100644 --- a/browser/websocket/_codeBlock.ts +++ b/browser/websocket/_codeBlock.ts @@ -1,4 +1,4 @@ -import { TinyCodeBlock } from "../../rest/getCodeBlocks.ts"; +import type { TinyCodeBlock } from "../../rest/getCodeBlocks.ts"; /** コードブロックのタイトル行の情報を保持しておくためのinterface */ export interface CodeTitle { diff --git a/browser/websocket/deletePage.ts b/browser/websocket/deletePage.ts index fe2f096..f287309 100644 --- a/browser/websocket/deletePage.ts +++ b/browser/websocket/deletePage.ts @@ -1,5 +1,5 @@ -import { push, PushOptions, RetryError } from "./push.ts"; -import { Result } from "../../rest/util.ts"; +import { push, type PushOptions, type RetryError } from "./push.ts"; +import type { Result } from "../../rest/util.ts"; export type DeletePageOptions = PushOptions; diff --git a/browser/websocket/findMetadata.ts b/browser/websocket/findMetadata.ts index b2e41d2..7f13e60 100644 --- a/browser/websocket/findMetadata.ts +++ b/browser/websocket/findMetadata.ts @@ -1,4 +1,4 @@ -import { BaseLine, Node, parse } from "../../deps/scrapbox.ts"; +import { type BaseLine, type Node, parse } from "../../deps/scrapbox.ts"; import { toTitleLc } from "../../title.ts"; import { parseYoutube } from "../../parser/youtube.ts"; diff --git a/browser/websocket/isSimpleCodeFile.test.ts b/browser/websocket/isSimpleCodeFile.test.ts index 19a1761..acf7973 100644 --- a/browser/websocket/isSimpleCodeFile.test.ts +++ b/browser/websocket/isSimpleCodeFile.test.ts @@ -1,6 +1,6 @@ import { assert, assertFalse } from "../../deps/testing.ts"; import { isSimpleCodeFile } from "./isSimpleCodeFile.ts"; -import { SimpleCodeFile } from "./updateCodeFile.ts"; +import type { SimpleCodeFile } from "./updateCodeFile.ts"; const codeFile: SimpleCodeFile = { filename: "filename", diff --git a/browser/websocket/isSimpleCodeFile.ts b/browser/websocket/isSimpleCodeFile.ts index 3aabccf..f85436f 100644 --- a/browser/websocket/isSimpleCodeFile.ts +++ b/browser/websocket/isSimpleCodeFile.ts @@ -1,4 +1,4 @@ -import { SimpleCodeFile } from "./updateCodeFile.ts"; +import type { SimpleCodeFile } from "./updateCodeFile.ts"; /** objectがSimpleCodeFile型かどうかを判別する */ export function isSimpleCodeFile(obj: unknown): obj is SimpleCodeFile { diff --git a/browser/websocket/listen.ts b/browser/websocket/listen.ts index 524c12f..dcdd795 100644 --- a/browser/websocket/listen.ts +++ b/browser/websocket/listen.ts @@ -1,7 +1,7 @@ import { - ProjectUpdatesStreamCommit, - ProjectUpdatesStreamEvent, - Socket, + type ProjectUpdatesStreamCommit, + type ProjectUpdatesStreamEvent, + type Socket, socketIO, wrap, } from "../../deps/socket.ts"; diff --git a/browser/websocket/makeChanges.ts b/browser/websocket/makeChanges.ts index 0cda36b..267ac8f 100644 --- a/browser/websocket/makeChanges.ts +++ b/browser/websocket/makeChanges.ts @@ -1,5 +1,5 @@ import { diffToChanges } from "./diffToChanges.ts"; -import { Page } from "../../deps/scrapbox-rest.ts"; +import type { Page } from "../../deps/scrapbox-rest.ts"; import type { Change } from "../../deps/socket.ts"; import { findMetadata, getHelpfeels } from "./findMetadata.ts"; import { isSameArray } from "./isSameArray.ts"; diff --git a/browser/websocket/patch.ts b/browser/websocket/patch.ts index 0c6260f..1afe546 100644 --- a/browser/websocket/patch.ts +++ b/browser/websocket/patch.ts @@ -1,9 +1,9 @@ -import { Change, DeletePageChange, PinChange } from "../../deps/socket.ts"; +import type { Change, DeletePageChange, PinChange } from "../../deps/socket.ts"; import { makeChanges } from "./makeChanges.ts"; -import { Line, Page } from "../../deps/scrapbox-rest.ts"; -import { push, PushOptions, RetryError } from "./push.ts"; +import type { Line, Page } from "../../deps/scrapbox-rest.ts"; +import { push, type PushOptions, type RetryError } from "./push.ts"; import { suggestUnDupTitle } from "./suggestUnDupTitle.ts"; -import { Result } from "../../rest/util.ts"; +import type { Result } from "../../rest/util.ts"; export type PatchOptions = PushOptions; diff --git a/browser/websocket/pin.ts b/browser/websocket/pin.ts index 57fb97e..e3065e4 100644 --- a/browser/websocket/pin.ts +++ b/browser/websocket/pin.ts @@ -1,6 +1,6 @@ -import { Change, Socket } from "../../deps/socket.ts"; -import { push, PushOptions, RetryError } from "./push.ts"; -import { Result } from "../../rest/util.ts"; +import type { Change, Socket } from "../../deps/socket.ts"; +import { push, type PushOptions, type RetryError } from "./push.ts"; +import type { Result } from "../../rest/util.ts"; export interface PinOptions extends PushOptions { /** ピン留め対象のページが存在しないときの振る舞いを変えるoption diff --git a/browser/websocket/pull.ts b/browser/websocket/pull.ts index 619ec7a..39a50d9 100644 --- a/browser/websocket/pull.ts +++ b/browser/websocket/pull.ts @@ -1,4 +1,4 @@ -import { Page } from "../../deps/scrapbox-rest.ts"; +import type { Page } from "../../deps/scrapbox-rest.ts"; import { getPage } from "../../rest/pages.ts"; export const pull = async ( diff --git a/browser/websocket/push.ts b/browser/websocket/push.ts index 29c27b3..1585241 100644 --- a/browser/websocket/push.ts +++ b/browser/websocket/push.ts @@ -1,22 +1,22 @@ import { - Change, - DeletePageChange, - PageCommit, - PageCommitError, - PageCommitResponse, - PinChange, - Socket, + type Change, + type DeletePageChange, + type PageCommit, + type PageCommitError, + type PageCommitResponse, + type PinChange, + type Socket, socketIO, - TimeoutError, - UnexpectedError, + type TimeoutError, + type UnexpectedError, wrap, } from "../../deps/socket.ts"; import { connect, disconnect } from "./socket.ts"; import { getProjectId, getUserId } from "./id.ts"; import { pull } from "./pull.ts"; -import { Page } from "../../deps/scrapbox-rest.ts"; -import { sleep } from "../../sleep.ts"; -import { Result } from "../../rest/util.ts"; +import type { Page } from "../../deps/scrapbox-rest.ts"; +import { delay } from "@std/async/delay"; +import type { Result } from "../../rest/util.ts"; export interface PushOptions { /** 外部からSocketを指定したいときに使う */ @@ -126,12 +126,12 @@ export const push = async ( throw error; } if (name === "TimeoutError" || name === "SocketIOError") { - await sleep(3000); + await delay(3000); // go back to the push loop continue; } if (name === "NotFastForwardError") { - await sleep(1000); + await delay(1000); page = { ...await pull(project, title), projectId: page.projectId, diff --git a/browser/websocket/socket.ts b/browser/websocket/socket.ts index 4fed4b4..fbaa733 100644 --- a/browser/websocket/socket.ts +++ b/browser/websocket/socket.ts @@ -1,4 +1,4 @@ -import { Socket, socketIO } from "../../deps/socket.ts"; +import { type Socket, socketIO } from "../../deps/socket.ts"; export type { Socket } from "../../deps/socket.ts"; /** 新しいsocketを作る */ diff --git a/browser/websocket/updateCodeBlock.ts b/browser/websocket/updateCodeBlock.ts index 9654aa1..8191897 100644 --- a/browser/websocket/updateCodeBlock.ts +++ b/browser/websocket/updateCodeBlock.ts @@ -1,12 +1,16 @@ -import { Line } from "../../deps/scrapbox-rest.ts"; -import { DeleteChange, InsertChange, UpdateChange } from "../../deps/socket.ts"; -import { TinyCodeBlock } from "../../rest/getCodeBlocks.ts"; +import type { Line } from "../../deps/scrapbox-rest.ts"; +import type { + DeleteChange, + InsertChange, + UpdateChange, +} from "../../deps/socket.ts"; +import type { TinyCodeBlock } from "../../rest/getCodeBlocks.ts"; import { diffToChanges } from "./diffToChanges.ts"; import { isSimpleCodeFile } from "./isSimpleCodeFile.ts"; -import { SimpleCodeFile } from "./updateCodeFile.ts"; +import type { SimpleCodeFile } from "./updateCodeFile.ts"; import { countBodyIndent, extractFromCodeTitle } from "./_codeBlock.ts"; -import { push, PushOptions, RetryError } from "./push.ts"; -import { Result } from "../../rest/util.ts"; +import { push, type PushOptions, type RetryError } from "./push.ts"; +import type { Result } from "../../rest/util.ts"; export interface UpdateCodeBlockOptions extends PushOptions { /** `true`でデバッグ出力ON */ diff --git a/browser/websocket/updateCodeFile.ts b/browser/websocket/updateCodeFile.ts index 0ccf88c..851b300 100644 --- a/browser/websocket/updateCodeFile.ts +++ b/browser/websocket/updateCodeFile.ts @@ -1,11 +1,15 @@ import type { Line } from "../../deps/scrapbox-rest.ts"; -import { DeleteChange, InsertChange, UpdateChange } from "../../deps/socket.ts"; -import { getCodeBlocks, TinyCodeBlock } from "../../rest/getCodeBlocks.ts"; +import type { + DeleteChange, + InsertChange, + UpdateChange, +} from "../../deps/socket.ts"; +import { getCodeBlocks, type TinyCodeBlock } from "../../rest/getCodeBlocks.ts"; import { createNewLineId } from "./id.ts"; import { diff, toExtendedChanges } from "../../deps/onp.ts"; import { countBodyIndent } from "./_codeBlock.ts"; -import { push, PushOptions, RetryError } from "./push.ts"; -import { Result } from "../../rest/util.ts"; +import { push, type PushOptions, type RetryError } from "./push.ts"; +import type { Result } from "../../rest/util.ts"; /** コードブロックの上書きに使う情報のinterface */ export interface SimpleCodeFile { diff --git a/deno.jsonc b/deno.jsonc new file mode 100644 index 0000000..75d6c3a --- /dev/null +++ b/deno.jsonc @@ -0,0 +1,44 @@ +{ + "name": "@takker/scrapbox-userscript-std", + "version": "0.0.0", + "tasks": { + "check": "deno fmt && deno lint && deno check --remote **/*.ts && deno test --allow-read", + "check:dry": "deno fmt --check && deno lint && deno check --remote **/*.ts && deno test --allow-read", + "update:check": "deno run --allow-env --allow-read --allow-write=.,'~/.local/share/deno-wasmbuild' --allow-run=git,deno --allow-net=deno.land,raw.githubusercontent.com,esm.sh,jsr.io,registry.npmjs.org jsr:@molt/cli@0.19", + "update": "deno task update:check --write", + "publish:check": "deno task check:dry && deno publish --dry-run --allow-dirty", + "publish": "deno run --allow-env --allow-run=deno --allow-read --allow-write=deno.jsonc jsr:@david/publish-on-tag@0.1.x" + }, + "imports": { + "@cosense/types/rest": "jsr:@cosense/types@0.10/rest", + "@cosense/types/userscript": "jsr:@cosense/types@0.10/userscript", + "@progfay/scrapbox-parser": "jsr:@progfay/scrapbox-parser@9", + "@std/assert": "jsr:@std/assert@1", + "@std/async": "jsr:@std/async@1", + "@std/hash": "./vendor/deno.land/std@0.160.0/hash/md5.ts", + "@std/testing/snapshot": "jsr:@std/testing@0/snapshot", + "@takker/onp": "./vendor/raw.githubusercontent.com/takker99/onp/0.0.1/mod.ts", + "@takker/scrapbox-userscript-websocket": "./vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/mod.ts" + }, + "exports": { + ".": "./mod.ts", + "./rest": "./rest/mod.ts", + "./browser": "./browser/mod.ts", + "./browser/dom": "./browser/dom/mod.ts", + "./browser/websocket": "./browser/websocket/mod.ts", + "./text": "./text.ts" + }, + "compilerOptions": { + "lib": [ + "esnext", + "dom", + "dom.iterable", + "deno.ns" + ] + }, + "lint": { + "exclude": [ + "vendor/" + ] + } +} diff --git a/deno.lock b/deno.lock new file mode 100644 index 0000000..db35bc8 --- /dev/null +++ b/deno.lock @@ -0,0 +1,201 @@ +{ + "version": "3", + "packages": { + "specifiers": { + "jsr:@cosense/types@0.10": "jsr:@cosense/types@0.10.1", + "jsr:@progfay/scrapbox-parser@9": "jsr:@progfay/scrapbox-parser@9.0.0", + "jsr:@std/assert@1": "jsr:@std/assert@1.0.1", + "jsr:@std/assert@1.0.0-rc.2": "jsr:@std/assert@1.0.0-rc.2", + "jsr:@std/async@1": "jsr:@std/async@1.0.1", + "jsr:@std/fmt@^0.225.4": "jsr:@std/fmt@0.225.6", + "jsr:@std/fs@^1.0.0-rc.1": "jsr:@std/fs@1.0.0", + "jsr:@std/internal@^1.0.0": "jsr:@std/internal@1.0.1", + "jsr:@std/internal@^1.0.1": "jsr:@std/internal@1.0.1", + "jsr:@std/path@1.0.0-rc.2": "jsr:@std/path@1.0.0-rc.2", + "jsr:@std/path@^1.0.2": "jsr:@std/path@1.0.2", + "jsr:@std/testing@0": "jsr:@std/testing@0.225.3" + }, + "jsr": { + "@cosense/types@0.10.1": { + "integrity": "13d2488a02c7b0b035a265bc3299affbdab1ea5b607516379685965cd37b2058" + }, + "@progfay/scrapbox-parser@9.0.0": { + "integrity": "c559602926d6ddd0580ab0c945333d06ed6cbdd67d4c67557edce8b0bb4be978" + }, + "@std/assert@1.0.0-rc.2": { + "integrity": "0484eab1d76b55fca1c3beaff485a274e67dd3b9f065edcbe70030dfc0b964d3" + }, + "@std/assert@1.0.1": { + "integrity": "13590ef8e5854f59e4ad252fd987e83239a1bf1f16cb9c69c1d123ebb807a75b", + "dependencies": [ + "jsr:@std/internal@^1.0.1" + ] + }, + "@std/async@1.0.1": { + "integrity": "3c7f6324a8a1b47ca657e5a349b511c9a6c2c0729e9d66b223c9ecaac0753ecb" + }, + "@std/fmt@0.225.6": { + "integrity": "aba6aea27f66813cecfd9484e074a9e9845782ab0685c030e453a8a70b37afc8" + }, + "@std/fs@1.0.0": { + "integrity": "d72e4a125af7168d717a2ed1dca77a728b422b0d138fd20579e3fa41a77da943", + "dependencies": [ + "jsr:@std/path@^1.0.2" + ] + }, + "@std/internal@1.0.1": { + "integrity": "6f8c7544d06a11dd256c8d6ba54b11ed870aac6c5aeafff499892662c57673e6" + }, + "@std/path@1.0.0-rc.2": { + "integrity": "39f20d37a44d1867abac8d91c169359ea6e942237a45a99ee1e091b32b921c7d" + }, + "@std/path@1.0.2": { + "integrity": "a452174603f8c620bd278a380c596437a9eef50c891c64b85812f735245d9ec7" + }, + "@std/testing@0.225.3": { + "integrity": "348c24d0479d44ab3dbb4f26170f242e19f24051b45935d4a9e7ca0ab7e37780", + "dependencies": [ + "jsr:@std/assert@1.0.0-rc.2", + "jsr:@std/fmt@^0.225.4", + "jsr:@std/fs@^1.0.0-rc.1", + "jsr:@std/internal@^1.0.0", + "jsr:@std/path@1.0.0-rc.2" + ] + } + } + }, + "remote": { + "https://deno.land/std@0.160.0/encoding/hex.ts": "4cc5324417cbb4ac9b828453d35aed45b9cc29506fad658f1f138d981ae33795", + "https://deno.land/std@0.160.0/hash/md5.ts": "5df247e8d9e0abeb555ed8ff39d39c0c3240f52847bfb72e363ad582a102527c", + "https://deno.land/std@0.160.0/hash/md5.ts#=": "5df247e8d9e0abeb555ed8ff39d39c0c3240f52847bfb72e363ad582a102527c", + "https://deno.land/std@0.224.0/assert/_constants.ts": "a271e8ef5a573f1df8e822a6eb9d09df064ad66a4390f21b3e31f820a38e0975", + "https://deno.land/std@0.224.0/assert/assert.ts": "09d30564c09de846855b7b071e62b5974b001bb72a4b797958fe0660e7849834", + "https://deno.land/std@0.224.0/assert/assert_almost_equals.ts": "9e416114322012c9a21fa68e187637ce2d7df25bcbdbfd957cd639e65d3cf293", + "https://deno.land/std@0.224.0/assert/assert_array_includes.ts": "14c5094471bc8e4a7895fc6aa5a184300d8a1879606574cb1cd715ef36a4a3c7", + "https://deno.land/std@0.224.0/assert/assert_equals.ts": "3bbca947d85b9d374a108687b1a8ba3785a7850436b5a8930d81f34a32cb8c74", + "https://deno.land/std@0.224.0/assert/assert_exists.ts": "43420cf7f956748ae6ed1230646567b3593cb7a36c5a5327269279c870c5ddfd", + "https://deno.land/std@0.224.0/assert/assert_false.ts": "3e9be8e33275db00d952e9acb0cd29481a44fa0a4af6d37239ff58d79e8edeff", + "https://deno.land/std@0.224.0/assert/assert_greater.ts": "5e57b201fd51b64ced36c828e3dfd773412c1a6120c1a5a99066c9b261974e46", + "https://deno.land/std@0.224.0/assert/assert_greater_or_equal.ts": "9870030f997a08361b6f63400273c2fb1856f5db86c0c3852aab2a002e425c5b", + "https://deno.land/std@0.224.0/assert/assert_instance_of.ts": "e22343c1fdcacfaea8f37784ad782683ec1cf599ae9b1b618954e9c22f376f2c", + "https://deno.land/std@0.224.0/assert/assert_is_error.ts": "f856b3bc978a7aa6a601f3fec6603491ab6255118afa6baa84b04426dd3cc491", + "https://deno.land/std@0.224.0/assert/assert_less.ts": "60b61e13a1982865a72726a5fa86c24fad7eb27c3c08b13883fb68882b307f68", + "https://deno.land/std@0.224.0/assert/assert_less_or_equal.ts": "d2c84e17faba4afe085e6c9123a63395accf4f9e00150db899c46e67420e0ec3", + "https://deno.land/std@0.224.0/assert/assert_match.ts": "ace1710dd3b2811c391946954234b5da910c5665aed817943d086d4d4871a8b7", + "https://deno.land/std@0.224.0/assert/assert_not_equals.ts": "78d45dd46133d76ce624b2c6c09392f6110f0df9b73f911d20208a68dee2ef29", + "https://deno.land/std@0.224.0/assert/assert_not_instance_of.ts": "3434a669b4d20cdcc5359779301a0588f941ffdc2ad68803c31eabdb4890cf7a", + "https://deno.land/std@0.224.0/assert/assert_not_match.ts": "df30417240aa2d35b1ea44df7e541991348a063d9ee823430e0b58079a72242a", + "https://deno.land/std@0.224.0/assert/assert_not_strict_equals.ts": "37f73880bd672709373d6dc2c5f148691119bed161f3020fff3548a0496f71b8", + "https://deno.land/std@0.224.0/assert/assert_object_match.ts": "411450fd194fdaabc0089ae68f916b545a49d7b7e6d0026e84a54c9e7eed2693", + "https://deno.land/std@0.224.0/assert/assert_rejects.ts": "4bee1d6d565a5b623146a14668da8f9eb1f026a4f338bbf92b37e43e0aa53c31", + "https://deno.land/std@0.224.0/assert/assert_strict_equals.ts": "b4f45f0fd2e54d9029171876bd0b42dd9ed0efd8f853ab92a3f50127acfa54f5", + "https://deno.land/std@0.224.0/assert/assert_string_includes.ts": "496b9ecad84deab72c8718735373feb6cdaa071eb91a98206f6f3cb4285e71b8", + "https://deno.land/std@0.224.0/assert/assert_throws.ts": "c6508b2879d465898dab2798009299867e67c570d7d34c90a2d235e4553906eb", + "https://deno.land/std@0.224.0/assert/assertion_error.ts": "ba8752bd27ebc51f723702fac2f54d3e94447598f54264a6653d6413738a8917", + "https://deno.land/std@0.224.0/assert/equal.ts": "bddf07bb5fc718e10bb72d5dc2c36c1ce5a8bdd3b647069b6319e07af181ac47", + "https://deno.land/std@0.224.0/assert/fail.ts": "0eba674ffb47dff083f02ced76d5130460bff1a9a68c6514ebe0cdea4abadb68", + "https://deno.land/std@0.224.0/assert/mod.ts": "48b8cb8a619ea0b7958ad7ee9376500fe902284bb36f0e32c598c3dc34cbd6f3", + "https://deno.land/std@0.224.0/assert/unimplemented.ts": "8c55a5793e9147b4f1ef68cd66496b7d5ba7a9e7ca30c6da070c1a58da723d73", + "https://deno.land/std@0.224.0/assert/unreachable.ts": "5ae3dbf63ef988615b93eb08d395dda771c96546565f9e521ed86f6510c29e19", + "https://deno.land/std@0.224.0/fmt/colors.ts": "508563c0659dd7198ba4bbf87e97f654af3c34eb56ba790260f252ad8012e1c5", + "https://deno.land/std@0.224.0/fs/_get_file_info_type.ts": "da7bec18a7661dba360a1db475b826b18977582ce6fc9b25f3d4ee0403fe8cbd", + "https://deno.land/std@0.224.0/fs/_to_path_string.ts": "29bfc9c6c112254961d75cbf6ba814d6de5349767818eb93090cecfa9665591e", + "https://deno.land/std@0.224.0/fs/ensure_dir.ts": "51a6279016c65d2985f8803c848e2888e206d1b510686a509fa7cc34ce59d29f", + "https://deno.land/std@0.224.0/fs/ensure_file.ts": "67608cf550529f3d4aa1f8b6b36bf817bdc40b14487bf8f60e61cbf68f507cf3", + "https://deno.land/std@0.224.0/internal/diff.ts": "6234a4b493ebe65dc67a18a0eb97ef683626a1166a1906232ce186ae9f65f4e6", + "https://deno.land/std@0.224.0/internal/format.ts": "0a98ee226fd3d43450245b1844b47003419d34d210fa989900861c79820d21c2", + "https://deno.land/std@0.224.0/internal/mod.ts": "534125398c8e7426183e12dc255bb635d94e06d0f93c60a297723abe69d3b22e", + "https://deno.land/std@0.224.0/path/_common/assert_path.ts": "dbdd757a465b690b2cc72fc5fb7698c51507dec6bfafce4ca500c46b76ff7bd8", + "https://deno.land/std@0.224.0/path/_common/constants.ts": "dc5f8057159f4b48cd304eb3027e42f1148cf4df1fb4240774d3492b5d12ac0c", + "https://deno.land/std@0.224.0/path/_common/dirname.ts": "684df4aa71a04bbcc346c692c8485594fc8a90b9408dfbc26ff32cf3e0c98cc8", + "https://deno.land/std@0.224.0/path/_common/from_file_url.ts": "d672bdeebc11bf80e99bf266f886c70963107bdd31134c4e249eef51133ceccf", + "https://deno.land/std@0.224.0/path/_common/normalize_string.ts": "33edef773c2a8e242761f731adeb2bd6d683e9c69e4e3d0092985bede74f4ac3", + "https://deno.land/std@0.224.0/path/_common/strip_trailing_separators.ts": "7024a93447efcdcfeaa9339a98fa63ef9d53de363f1fbe9858970f1bba02655a", + "https://deno.land/std@0.224.0/path/_common/to_file_url.ts": "7f76adbc83ece1bba173e6e98a27c647712cab773d3f8cbe0398b74afc817883", + "https://deno.land/std@0.224.0/path/_interface.ts": "8dfeb930ca4a772c458a8c7bbe1e33216fe91c253411338ad80c5b6fa93ddba0", + "https://deno.land/std@0.224.0/path/_os.ts": "8fb9b90fb6b753bd8c77cfd8a33c2ff6c5f5bc185f50de8ca4ac6a05710b2c15", + "https://deno.land/std@0.224.0/path/dirname.ts": "85bd955bf31d62c9aafdd7ff561c4b5fb587d11a9a5a45e2b01aedffa4238a7c", + "https://deno.land/std@0.224.0/path/from_file_url.ts": "911833ae4fd10a1c84f6271f36151ab785955849117dc48c6e43b929504ee069", + "https://deno.land/std@0.224.0/path/parse.ts": "77ad91dcb235a66c6f504df83087ce2a5471e67d79c402014f6e847389108d5a", + "https://deno.land/std@0.224.0/path/posix/_util.ts": "1e3937da30f080bfc99fe45d7ed23c47dd8585c5e473b2d771380d3a6937cf9d", + "https://deno.land/std@0.224.0/path/posix/dirname.ts": "76cd348ffe92345711409f88d4d8561d8645353ac215c8e9c80140069bf42f00", + "https://deno.land/std@0.224.0/path/posix/from_file_url.ts": "951aee3a2c46fd0ed488899d024c6352b59154c70552e90885ed0c2ab699bc40", + "https://deno.land/std@0.224.0/path/posix/is_absolute.ts": "cebe561ad0ae294f0ce0365a1879dcfca8abd872821519b4fcc8d8967f888ede", + "https://deno.land/std@0.224.0/path/posix/parse.ts": "09dfad0cae530f93627202f28c1befa78ea6e751f92f478ca2cc3b56be2cbb6a", + "https://deno.land/std@0.224.0/path/posix/resolve.ts": "08b699cfeee10cb6857ccab38fa4b2ec703b0ea33e8e69964f29d02a2d5257cf", + "https://deno.land/std@0.224.0/path/posix/to_file_url.ts": "7aa752ba66a35049e0e4a4be5a0a31ac6b645257d2e031142abb1854de250aaf", + "https://deno.land/std@0.224.0/path/resolve.ts": "a6f977bdb4272e79d8d0ed4333e3d71367cc3926acf15ac271f1d059c8494d8d", + "https://deno.land/std@0.224.0/path/to_file_url.ts": "88f049b769bce411e2d2db5bd9e6fd9a185a5fbd6b9f5ad8f52bef517c4ece1b", + "https://deno.land/std@0.224.0/path/windows/_util.ts": "d5f47363e5293fced22c984550d5e70e98e266cc3f31769e1710511803d04808", + "https://deno.land/std@0.224.0/path/windows/dirname.ts": "33e421be5a5558a1346a48e74c330b8e560be7424ed7684ea03c12c21b627bc9", + "https://deno.land/std@0.224.0/path/windows/from_file_url.ts": "ced2d587b6dff18f963f269d745c4a599cf82b0c4007356bd957cb4cb52efc01", + "https://deno.land/std@0.224.0/path/windows/is_absolute.ts": "4a8f6853f8598cf91a835f41abed42112cebab09478b072e4beb00ec81f8ca8a", + "https://deno.land/std@0.224.0/path/windows/parse.ts": "08804327b0484d18ab4d6781742bf374976de662f8642e62a67e93346e759707", + "https://deno.land/std@0.224.0/path/windows/resolve.ts": "8dae1dadfed9d46ff46cc337c9525c0c7d959fb400a6308f34595c45bdca1972", + "https://deno.land/std@0.224.0/path/windows/to_file_url.ts": "40e560ee4854fe5a3d4d12976cef2f4e8914125c81b11f1108e127934ced502e", + "https://deno.land/std@0.224.0/testing/snapshot.ts": "35ca1c8e8bfb98d7b7e794f1b7be8d992483fcff572540e41396f22a5bddb944", + "https://esm.sh/@progfay/scrapbox-parser@9.0.0": "24b6a5a7b95e3b8f49a259fce1f39b0d9c333b2c8afc71d844d551c47473b3b1", + "https://esm.sh/v135/@progfay/scrapbox-parser@9.0.0/denonext/scrapbox-parser.mjs": "36ea0381aaf840f8e1d177d3f349d191e70a2b33292010b87e84ea1d34fd4937", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/base.ts": "63bd526c652edbdd43aa86b119828b87828b25dfbb997ce521437cc6fc40fbcb", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/baseStore.ts": "b05ed2f2de45d187afc8f9fbb4767b209929cc6924f67d1d6f252eb3bb64c32f", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/blocks.ts": "d37c6bb33b600ece0bfeb5b63246300c567bdf38e559adf01e1d26c967f8999f", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/change.ts": "9b4d9af65a9d5aa024aa84acb62128da8db3c8892f3a0256ca89fde84ab50485", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/commit.ts": "0c576ba285c69d13ee653d9ffb01bf30df8243f3f718ef34f821be10c3cbe0e2", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/deps/events.ts": "ee8d76b320f2dfa4b128dfd288665a9be938b1b91e92c7fe3cca7cd1a7d0b712", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/deps/react.ts": "615586e4241cfa13f2c17c019c0775be981067558b7611aadb422102fb72c27b", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/error.ts": "d48e7ded2683f47a778a0793e1a142baae75582ccbe9bb1c8e115787a6bcc33e", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/eventName.ts": "c5c9074c379290250ef4f19abe510c43cfbd08a6704b5857c8a7c054b0a2e7cc", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/layout.ts": "11cc0e9e80e56ae5fdc09d5a057ca052e7bf829b15b2fd9bb7e59a549c476a30", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/anchor.ts": "3d040039a8d69d401bc41e7ff995083e9ebadbbf263680ee16a7712a8e21b56e", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/audio.ts": "81ae28b140b50034b0186ed0465e9b41d902a7370786b4641700b0690d1d6f26", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/audioLink.ts": "2038dc326e9037140100d2b3d4346b027d52a47ecbf6ab24e4e02d1e65f3d253", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/blank.ts": "356af0417b138e4a71eea1683759a56a26b8263df28a385458cbe51b02986856", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/code.ts": "f20ab3c7bffb283f41190565aa5a8bc80ea93f752f74d1e471fc5a0c93c23800", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/decoration.ts": "c88db9edabaec8ec13678bb63e81df678fb6e3a79a7c41b5831ac2bdc7ab5534", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/formula.ts": "38f6a2fe4ed2fafc1db491f21f0aeb8a6d554f016f6cca9d27926520d7039f69", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/googleMap.ts": "6f76fc80ed68254264428272e46e3f45b9c17bcd0254b9c755246f9d3546a09a", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/gyazo.ts": "e3f1028ed72fe58dc24ac2a6d2d5ba04357bf349feea5b3f839577f2b37895e0", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/gyazoLink.ts": "291d201a78593785b8fa8dc26a0ca7e0f3de32f66a1d5564fb145748accd52b8", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/hashTag.ts": "8681d33efa0ed2c11dec79b0de54e2ecae1eee1dba0500727210d5795d46bdca", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/icon.ts": "2de232a72a8697d3a53e441e85c412f680c6828ea34859ffeffec61c42ef8bc7", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/image.ts": "8d74736ab40d73f7de0227dc9e084723d3b1a11e419808db45af4c64e75ef166", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/imageLink.ts": "ce0c51de550b95fda1e43eba6779b62e2ec1b088e77c67014cb39d610f6c8d5e", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/indent.ts": "8713c29f254e3d0f9a580eb9e67cb755e4984c9ca5a9d57759e4adbdeb113b94", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/link.ts": "8941e9ba0aad88e6e70331f9a2242938cf5023aa42a4c0ea7cbb0f536471696a", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/node.ts": "21eddbc8ffb7d9e9c4cbeb2ddb3cc00272aef2cf8276a35433b52c5c6c377ec8", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/plainText.ts": "1c6cf1bb4f11c950176ed7f2a0703a4b0f84ca3adc9e99dcbe5fc07185989c5a", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/quote.ts": "6c7a219b7325cf9ed757a5924d9f1d3731b19ed526705499f2c5561ebd7c8410", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/spotify.ts": "db7fda4ad020c411291dda9fb134e0f993063637fc3ada11c393806e7c537789", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/strong.ts": "28e243dfb5928a628b72225eb2e39ae0c0b0d088f4ceac1ce2288582f4b73797", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/unit.ts": "c5b9e5528c1b6da08794e2ebf61e25c0c2bf04f2a45682d16fd802a4c50e895a", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/url.ts": "ee63873dbce3e8edb547f0e44e8400cb875c00edb548ca6abf40d72a9f11b714", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/urlLink.ts": "410b062607137f75603b3d19585a0ac5605e0721f306840c872c0ea6c4e8ed9b", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/video.ts": "d35692e25001533636d7a3f8bc133718794c3f5ecd6f49768f9da9d52f1ed833", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/vimeo.ts": "43f97bb9312817c1503edeec08f056c9ebb407b8746e071a9ce161b2d4bc0525", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/node/youtube.ts": "8c7b9bfe15e0a2d17ae79a272d770effded2a78d75ab9c585c4bbc2a04c26978", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/pageMenu.ts": "97c843bb61c6e535011cbbf73099d68ed3cceb72fdfcc222db69ce32fc6b3b34", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/response.ts": "abed5a47197cd1b13386017b15d98e4f85a73d25a1d678fd131af7ef4c6093f8", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/rest.ts": "4620da5f7c9cddf5a40241b842184df57d1162fa0f549f93c0722f9275f12533", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/scrapbox.ts": "18c9bf3d47a5a9ede8d0de982dc233ef80251cbe294719f964a1041689b2e9bd", + "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/userscript.ts": "c25143a34f1a1ec5c7430fc95735b4fefa18a16be41b44d3bf3050b64ed89d1d", + "https://raw.githubusercontent.com/takker99/onp/0.0.1/mod.ts": "7a98e55b8f1ba5db5d5e80e7df455989679d191c423cdd7688d26fc75ea685a2", + "https://raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/mod.ts": "efd78be03f19d4f84dc159a9f891db7cffd8b25171edaf8d64b4e7b827f05d28", + "https://raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/socket.ts": "4aa9502d2dfe3cac5076f7eb6cab560baae66db2198eed5e1d7659774ad0ce21", + "https://raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types.ts": "2d034ec1aa66a0e11232adc179dc6030c64c5968bbc8306a27e3559582b6f400", + "https://raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/emitter.ts": "a319c4200f9c771319d97f8235ce24126d27df4dfc3de1bf59fafa3bf5659426", + "https://raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/index.ts": "e0c9549274431867631ae84fa1dab2908e7dd53d6ced4a6fad8a5123f7f52bc8", + "https://raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/manager.ts": "54f0b8c9e88b6952f0f1bd37429ba23c28879f3685a6f3cb0354cd0cbaeef808", + "https://raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/parser.ts": "b23cf18fa302e64def6744e346c0b9e2f0042d0efb4a10583f3b29ef0478e423", + "https://raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/socket.ts": "923b0dd961e038b7f077adec9e96629cc5a7a1d50dc499e8503e1608a4f777b0", + "https://raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/typed-events.ts": "bea1abae38c17f77e8887a1d3b4e80684632a335f616b8987459ba3d2a863d3a" + }, + "workspace": { + "dependencies": [ + "jsr:@cosense/types@0.10", + "jsr:@progfay/scrapbox-parser@9", + "jsr:@std/assert@1", + "jsr:@std/async@1", + "jsr:@std/testing@0" + ] + } +} diff --git a/deps/hash.ts b/deps/hash.ts index 6780d11..9958823 100644 --- a/deps/hash.ts +++ b/deps/hash.ts @@ -1 +1 @@ -export { Md5 } from "https://deno.land/std@0.160.0/hash/md5.ts#="; +export { Md5 } from "@std/hash"; diff --git a/deps/onp.ts b/deps/onp.ts index fe489c5..c1c13aa 100644 --- a/deps/onp.ts +++ b/deps/onp.ts @@ -1 +1 @@ -export * from "https://raw.githubusercontent.com/takker99/onp/0.0.1/mod.ts"; +export * from "@takker/onp"; diff --git a/deps/scrapbox-rest.ts b/deps/scrapbox-rest.ts index f6cfa5b..660036a 100644 --- a/deps/scrapbox-rest.ts +++ b/deps/scrapbox-rest.ts @@ -26,4 +26,4 @@ export type { SessionError, Snapshot, TweetInfo, -} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/rest.ts"; +} from "@cosense/types/rest"; diff --git a/deps/scrapbox.ts b/deps/scrapbox.ts index 98efe9a..d3e17f1 100644 --- a/deps/scrapbox.ts +++ b/deps/scrapbox.ts @@ -1,9 +1,7 @@ export type { BaseLine, + BaseStore, Line, Scrapbox, -} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/userscript.ts"; -export type { - BaseStore, -} from "https://raw.githubusercontent.com/scrapbox-jp/types/0.9.0/baseStore.ts"; -export * from "https://esm.sh/@progfay/scrapbox-parser@9.0.0"; +} from "@cosense/types/userscript"; +export * from "@progfay/scrapbox-parser"; diff --git a/deps/socket.ts b/deps/socket.ts index c55cbdf..29a67ed 100644 --- a/deps/socket.ts +++ b/deps/socket.ts @@ -1 +1 @@ -export * from "https://raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/mod.ts"; +export * from "@takker/scrapbox-userscript-websocket"; diff --git a/deps/testing.ts b/deps/testing.ts index b1ce633..a165a85 100644 --- a/deps/testing.ts +++ b/deps/testing.ts @@ -1,2 +1,2 @@ -export * from "https://deno.land/std@0.224.0/assert/mod.ts"; -export * from "https://deno.land/std@0.224.0/testing/snapshot.ts"; +export * from "@std/assert"; +export * from "@std/testing/snapshot"; diff --git a/rest/auth.ts b/rest/auth.ts index fe54500..8d9173a 100644 --- a/rest/auth.ts +++ b/rest/auth.ts @@ -1,12 +1,5 @@ import { getProfile } from "./profile.ts"; -import { BaseOptions } from "./util.ts"; - -// scrapbox.io内なら`window._csrf`にCSRF tokenが入っている -declare global { - // globalThisに変数を宣言するには、`var`を使うしかない - // deno-lint-ignore no-var - var _csrf: string | undefined; -} +import type { BaseOptions } from "./util.ts"; /** HTTP headerのCookieに入れる文字列を作る * @@ -21,7 +14,8 @@ export const cookie = (sid: string): string => `connect.sid=${sid}`; export const getCSRFToken = async ( init?: BaseOptions, ): Promise => { - if (globalThis._csrf) return globalThis._csrf; + // deno-lint-ignore no-explicit-any + if ((globalThis as any)._csrf) return (globalThis as any)._csrf; const user = await getProfile(init); return user.csrfToken; diff --git a/rest/getCodeBlock.ts b/rest/getCodeBlock.ts index f4cdc9a..79cfde0 100644 --- a/rest/getCodeBlock.ts +++ b/rest/getCodeBlock.ts @@ -6,7 +6,7 @@ import type { import { cookie } from "./auth.ts"; import { makeError } from "./error.ts"; import { encodeTitleURI } from "../title.ts"; -import { BaseOptions, Result, setDefaults } from "./util.ts"; +import { type BaseOptions, type Result, setDefaults } from "./util.ts"; const getCodeBlock_toRequest: GetCodeBlock["toRequest"] = ( project, diff --git a/rest/getCodeBlocks.test.ts b/rest/getCodeBlocks.test.ts index e409e59..9c4967b 100644 --- a/rest/getCodeBlocks.test.ts +++ b/rest/getCodeBlocks.test.ts @@ -1,6 +1,4 @@ -/// - -import { Line } from "../deps/scrapbox-rest.ts"; +import type { Line } from "../deps/scrapbox-rest.ts"; import { assertEquals, assertSnapshot } from "../deps/testing.ts"; import { getCodeBlocks } from "./getCodeBlocks.ts"; diff --git a/rest/getCodeBlocks.ts b/rest/getCodeBlocks.ts index 549e026..a377f3f 100644 --- a/rest/getCodeBlocks.ts +++ b/rest/getCodeBlocks.ts @@ -1,7 +1,7 @@ import type { Line } from "../deps/scrapbox-rest.ts"; import { pull } from "../browser/websocket/pull.ts"; import { - CodeTitle, + type CodeTitle, extractFromCodeTitle, } from "../browser/websocket/_codeBlock.ts"; diff --git a/rest/getGyazoToken.ts b/rest/getGyazoToken.ts index daefb6c..462c04d 100644 --- a/rest/getGyazoToken.ts +++ b/rest/getGyazoToken.ts @@ -1,7 +1,7 @@ import type { NotLoggedInError } from "../deps/scrapbox-rest.ts"; import { cookie } from "./auth.ts"; import { makeError } from "./error.ts"; -import { BaseOptions, Result, setDefaults } from "./util.ts"; +import { type BaseOptions, type Result, setDefaults } from "./util.ts"; export interface GetGyazoTokenOptions extends BaseOptions { /** Gyazo Teamsのチーム名 diff --git a/rest/getTweetInfo.ts b/rest/getTweetInfo.ts index 4871b3e..b2e859f 100644 --- a/rest/getTweetInfo.ts +++ b/rest/getTweetInfo.ts @@ -6,7 +6,7 @@ import type { } from "../deps/scrapbox-rest.ts"; import { cookie, getCSRFToken } from "./auth.ts"; import { makeError } from "./error.ts"; -import { ExtendedOptions, Result, setDefaults } from "./util.ts"; +import { type ExtendedOptions, type Result, setDefaults } from "./util.ts"; /** 指定したTweetの情報を取得する * diff --git a/rest/getWebPageTitle.ts b/rest/getWebPageTitle.ts index 0e23309..ec7c4f7 100644 --- a/rest/getWebPageTitle.ts +++ b/rest/getWebPageTitle.ts @@ -5,7 +5,7 @@ import type { } from "../deps/scrapbox-rest.ts"; import { cookie, getCSRFToken } from "./auth.ts"; import { makeError } from "./error.ts"; -import { ExtendedOptions, Result, setDefaults } from "./util.ts"; +import { type ExtendedOptions, type Result, setDefaults } from "./util.ts"; /** 指定したURLのweb pageのtitleをscrapboxのserver経由で取得する * diff --git a/rest/link.ts b/rest/link.ts index 576925f..546537c 100644 --- a/rest/link.ts +++ b/rest/link.ts @@ -6,7 +6,7 @@ import type { } from "../deps/scrapbox-rest.ts"; import { cookie } from "./auth.ts"; import { makeError } from "./error.ts"; -import { BaseOptions, Result, setDefaults } from "./util.ts"; +import { type BaseOptions, type Result, setDefaults } from "./util.ts"; /** 不正なfollowingIdを渡されたときに発生するエラー */ export interface InvalidFollowingIdError extends ErrorLike { diff --git a/rest/page-data.ts b/rest/page-data.ts index 6407979..21a0224 100644 --- a/rest/page-data.ts +++ b/rest/page-data.ts @@ -8,7 +8,12 @@ import type { } from "../deps/scrapbox-rest.ts"; import { cookie, getCSRFToken } from "./auth.ts"; import { makeError } from "./error.ts"; -import { BaseOptions, ExtendedOptions, Result, setDefaults } from "./util.ts"; +import { + type BaseOptions, + type ExtendedOptions, + type Result, + setDefaults, +} from "./util.ts"; /** projectにページをインポートする * * @param project - インポート先のprojectの名前 diff --git a/rest/pages.ts b/rest/pages.ts index 2306453..c8921c0 100644 --- a/rest/pages.ts +++ b/rest/pages.ts @@ -9,7 +9,7 @@ import type { import { cookie } from "./auth.ts"; import { makeError } from "./error.ts"; import { encodeTitleURI } from "../title.ts"; -import { BaseOptions, Result, setDefaults } from "./util.ts"; +import { type BaseOptions, type Result, setDefaults } from "./util.ts"; /** Options for `getPage()` */ export interface GetPageOption extends BaseOptions { diff --git a/rest/profile.ts b/rest/profile.ts index f2386d5..81de3cf 100644 --- a/rest/profile.ts +++ b/rest/profile.ts @@ -1,6 +1,6 @@ import type { GuestUser, MemberUser } from "../deps/scrapbox-rest.ts"; import { cookie } from "./auth.ts"; -import { BaseOptions, setDefaults } from "./util.ts"; +import { type BaseOptions, setDefaults } from "./util.ts"; import { UnexpectedResponseError } from "./error.ts"; /** get user profile diff --git a/rest/project.ts b/rest/project.ts index fe8b7c5..5faea8a 100644 --- a/rest/project.ts +++ b/rest/project.ts @@ -9,7 +9,7 @@ import type { } from "../deps/scrapbox-rest.ts"; import { cookie } from "./auth.ts"; import { makeError } from "./error.ts"; -import { BaseOptions, Result, setDefaults } from "./util.ts"; +import { type BaseOptions, type Result, setDefaults } from "./util.ts"; export interface GetProject { /** /api/project/:project の要求を組み立てる diff --git a/rest/replaceLinks.ts b/rest/replaceLinks.ts index 630a9fc..3023be8 100644 --- a/rest/replaceLinks.ts +++ b/rest/replaceLinks.ts @@ -5,7 +5,7 @@ import type { } from "../deps/scrapbox-rest.ts"; import { cookie, getCSRFToken } from "./auth.ts"; import { makeError } from "./error.ts"; -import { ExtendedOptions, Result, setDefaults } from "./util.ts"; +import { type ExtendedOptions, type Result, setDefaults } from "./util.ts"; /** 指定したproject内の全てのリンクを書き換える * diff --git a/rest/search.ts b/rest/search.ts index 8884110..ff4bab6 100644 --- a/rest/search.ts +++ b/rest/search.ts @@ -8,7 +8,7 @@ import type { } from "../deps/scrapbox-rest.ts"; import { cookie } from "./auth.ts"; import { makeError } from "./error.ts"; -import { BaseOptions, Result, setDefaults } from "./util.ts"; +import { type BaseOptions, type Result, setDefaults } from "./util.ts"; /** search a project for pages * diff --git a/rest/snapshot.ts b/rest/snapshot.ts index 85d9973..1a9314b 100644 --- a/rest/snapshot.ts +++ b/rest/snapshot.ts @@ -7,7 +7,7 @@ import type { PageSnapshotResult, } from "../deps/scrapbox-rest.ts"; import { cookie } from "./auth.ts"; -import { BaseOptions, Result, setDefaults } from "./util.ts"; +import { type BaseOptions, type Result, setDefaults } from "./util.ts"; import { makeError } from "./error.ts"; /** 不正な`timestampId`を渡されたときに発生するエラー */ diff --git a/rest/table.ts b/rest/table.ts index d60b10b..2eb29c1 100644 --- a/rest/table.ts +++ b/rest/table.ts @@ -6,7 +6,7 @@ import type { import { cookie } from "./auth.ts"; import { makeError } from "./error.ts"; import { encodeTitleURI } from "../title.ts"; -import { BaseOptions, Result, setDefaults } from "./util.ts"; +import { type BaseOptions, type Result, setDefaults } from "./util.ts"; const getTable_toRequest: GetTable["toRequest"] = ( project, diff --git a/rest/uploadToGCS.ts b/rest/uploadToGCS.ts index 05642a0..b714fc8 100644 --- a/rest/uploadToGCS.ts +++ b/rest/uploadToGCS.ts @@ -1,5 +1,10 @@ import { cookie, getCSRFToken } from "./auth.ts"; -import { BaseOptions, ExtendedOptions, Result, setDefaults } from "./util.ts"; +import { + type BaseOptions, + type ExtendedOptions, + type Result, + setDefaults, +} from "./util.ts"; import { makeError, UnexpectedResponseError } from "./error.ts"; import type { ErrorLike, NotFoundError } from "../deps/scrapbox-rest.ts"; import { Md5 } from "../deps/hash.ts"; diff --git a/sleep.ts b/sleep.ts deleted file mode 100644 index 21b2281..0000000 --- a/sleep.ts +++ /dev/null @@ -1,6 +0,0 @@ -/** ミリ秒単位で待つ - * - * @param milliseconds 待ち時間 (ミリ秒) - */ -export const sleep = (milliseconds: number): Promise => - new Promise((resolve) => setTimeout(() => resolve(), milliseconds)); diff --git a/vendor/deno.land/std@0.160.0/encoding/hex.ts b/vendor/deno.land/std@0.160.0/encoding/hex.ts new file mode 100644 index 0000000..b23c857 --- /dev/null +++ b/vendor/deno.land/std@0.160.0/encoding/hex.ts @@ -0,0 +1,67 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// https://github.com/golang/go/blob/master/LICENSE +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. + +/** Port of the Go + * [encoding/hex](https://github.com/golang/go/blob/go1.12.5/src/encoding/hex/hex.go) + * library. + * + * This module is browser compatible. + * + * @module + */ + +const hexTable = new TextEncoder().encode("0123456789abcdef"); + +function errInvalidByte(byte: number) { + return new TypeError(`Invalid byte '${String.fromCharCode(byte)}'`); +} + +function errLength() { + return new RangeError("Odd length hex string"); +} + +/** Converts a hex character into its value. */ +function fromHexChar(byte: number): number { + // '0' <= byte && byte <= '9' + if (48 <= byte && byte <= 57) return byte - 48; + // 'a' <= byte && byte <= 'f' + if (97 <= byte && byte <= 102) return byte - 97 + 10; + // 'A' <= byte && byte <= 'F' + if (65 <= byte && byte <= 70) return byte - 65 + 10; + + throw errInvalidByte(byte); +} + +/** Encodes `src` into `src.length * 2` bytes. */ +export function encode(src: Uint8Array): Uint8Array { + const dst = new Uint8Array(src.length * 2); + for (let i = 0; i < dst.length; i++) { + const v = src[i]; + dst[i * 2] = hexTable[v >> 4]; + dst[i * 2 + 1] = hexTable[v & 0x0f]; + } + return dst; +} + +/** + * Decodes `src` into `src.length / 2` bytes. + * If the input is malformed, an error will be thrown. + */ +export function decode(src: Uint8Array): Uint8Array { + const dst = new Uint8Array(src.length / 2); + for (let i = 0; i < dst.length; i++) { + const a = fromHexChar(src[i * 2]); + const b = fromHexChar(src[i * 2 + 1]); + dst[i] = (a << 4) | b; + } + + if (src.length % 2 == 1) { + // Check for invalid char before reporting bad length, + // since the invalid char (if present) is an earlier problem. + fromHexChar(src[dst.length * 2]); + throw errLength(); + } + + return dst; +} diff --git a/vendor/deno.land/std@0.160.0/hash/md5.ts b/vendor/deno.land/std@0.160.0/hash/md5.ts new file mode 100644 index 0000000..0bd2dd4 --- /dev/null +++ b/vendor/deno.land/std@0.160.0/hash/md5.ts @@ -0,0 +1,251 @@ +// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license. +// This module is browser compatible. + +import * as hex from "../encoding/hex.ts"; + +const TYPE_ERROR_MSG = "md5: `data` is invalid type"; +const BLOCK_SIZE = 64; + +export type Message = string | ArrayBuffer; + +/** Md5 hash */ +export class Md5 { + #a: number; + #b: number; + #c: number; + #d: number; + #block: Uint8Array; + #pos: number; + #n0: number; + #n1: number; + + constructor() { + this.#a = 0x67452301; + this.#b = 0xefcdab89; + this.#c = 0x98badcfe; + this.#d = 0x10325476; + this.#block = new Uint8Array(BLOCK_SIZE); + this.#pos = 0; + this.#n0 = 0; + this.#n1 = 0; + } + + #addLength(len: number) { + let n0 = this.#n0; + n0 += len; + if (n0 > 0xffffffff) this.#n1 += 1; + this.#n0 = n0 >>> 0; + } + + #hash(block: Uint8Array) { + let a = this.#a; + let b = this.#b; + let c = this.#c; + let d = this.#d; + + const blk = (i: number): number => + block[i] | + (block[i + 1] << 8) | + (block[i + 2] << 16) | + (block[i + 3] << 24); + + const rol32 = (x: number, n: number): number => (x << n) | (x >>> (32 - n)); + + const x0 = blk(0); + const x1 = blk(4); + const x2 = blk(8); + const x3 = blk(12); + const x4 = blk(16); + const x5 = blk(20); + const x6 = blk(24); + const x7 = blk(28); + const x8 = blk(32); + const x9 = blk(36); + const xa = blk(40); + const xb = blk(44); + const xc = blk(48); + const xd = blk(52); + const xe = blk(56); + const xf = blk(60); + + // round 1 + a = b + rol32((((c ^ d) & b) ^ d) + a + x0 + 0xd76aa478, 7); + d = a + rol32((((b ^ c) & a) ^ c) + d + x1 + 0xe8c7b756, 12); + c = d + rol32((((a ^ b) & d) ^ b) + c + x2 + 0x242070db, 17); + b = c + rol32((((d ^ a) & c) ^ a) + b + x3 + 0xc1bdceee, 22); + a = b + rol32((((c ^ d) & b) ^ d) + a + x4 + 0xf57c0faf, 7); + d = a + rol32((((b ^ c) & a) ^ c) + d + x5 + 0x4787c62a, 12); + c = d + rol32((((a ^ b) & d) ^ b) + c + x6 + 0xa8304613, 17); + b = c + rol32((((d ^ a) & c) ^ a) + b + x7 + 0xfd469501, 22); + a = b + rol32((((c ^ d) & b) ^ d) + a + x8 + 0x698098d8, 7); + d = a + rol32((((b ^ c) & a) ^ c) + d + x9 + 0x8b44f7af, 12); + c = d + rol32((((a ^ b) & d) ^ b) + c + xa + 0xffff5bb1, 17); + b = c + rol32((((d ^ a) & c) ^ a) + b + xb + 0x895cd7be, 22); + a = b + rol32((((c ^ d) & b) ^ d) + a + xc + 0x6b901122, 7); + d = a + rol32((((b ^ c) & a) ^ c) + d + xd + 0xfd987193, 12); + c = d + rol32((((a ^ b) & d) ^ b) + c + xe + 0xa679438e, 17); + b = c + rol32((((d ^ a) & c) ^ a) + b + xf + 0x49b40821, 22); + + // round 2 + a = b + rol32((((b ^ c) & d) ^ c) + a + x1 + 0xf61e2562, 5); + d = a + rol32((((a ^ b) & c) ^ b) + d + x6 + 0xc040b340, 9); + c = d + rol32((((d ^ a) & b) ^ a) + c + xb + 0x265e5a51, 14); + b = c + rol32((((c ^ d) & a) ^ d) + b + x0 + 0xe9b6c7aa, 20); + a = b + rol32((((b ^ c) & d) ^ c) + a + x5 + 0xd62f105d, 5); + d = a + rol32((((a ^ b) & c) ^ b) + d + xa + 0x02441453, 9); + c = d + rol32((((d ^ a) & b) ^ a) + c + xf + 0xd8a1e681, 14); + b = c + rol32((((c ^ d) & a) ^ d) + b + x4 + 0xe7d3fbc8, 20); + a = b + rol32((((b ^ c) & d) ^ c) + a + x9 + 0x21e1cde6, 5); + d = a + rol32((((a ^ b) & c) ^ b) + d + xe + 0xc33707d6, 9); + c = d + rol32((((d ^ a) & b) ^ a) + c + x3 + 0xf4d50d87, 14); + b = c + rol32((((c ^ d) & a) ^ d) + b + x8 + 0x455a14ed, 20); + a = b + rol32((((b ^ c) & d) ^ c) + a + xd + 0xa9e3e905, 5); + d = a + rol32((((a ^ b) & c) ^ b) + d + x2 + 0xfcefa3f8, 9); + c = d + rol32((((d ^ a) & b) ^ a) + c + x7 + 0x676f02d9, 14); + b = c + rol32((((c ^ d) & a) ^ d) + b + xc + 0x8d2a4c8a, 20); + + // round 3 + a = b + rol32((b ^ c ^ d) + a + x5 + 0xfffa3942, 4); + d = a + rol32((a ^ b ^ c) + d + x8 + 0x8771f681, 11); + c = d + rol32((d ^ a ^ b) + c + xb + 0x6d9d6122, 16); + b = c + rol32((c ^ d ^ a) + b + xe + 0xfde5380c, 23); + a = b + rol32((b ^ c ^ d) + a + x1 + 0xa4beea44, 4); + d = a + rol32((a ^ b ^ c) + d + x4 + 0x4bdecfa9, 11); + c = d + rol32((d ^ a ^ b) + c + x7 + 0xf6bb4b60, 16); + b = c + rol32((c ^ d ^ a) + b + xa + 0xbebfbc70, 23); + a = b + rol32((b ^ c ^ d) + a + xd + 0x289b7ec6, 4); + d = a + rol32((a ^ b ^ c) + d + x0 + 0xeaa127fa, 11); + c = d + rol32((d ^ a ^ b) + c + x3 + 0xd4ef3085, 16); + b = c + rol32((c ^ d ^ a) + b + x6 + 0x04881d05, 23); + a = b + rol32((b ^ c ^ d) + a + x9 + 0xd9d4d039, 4); + d = a + rol32((a ^ b ^ c) + d + xc + 0xe6db99e5, 11); + c = d + rol32((d ^ a ^ b) + c + xf + 0x1fa27cf8, 16); + b = c + rol32((c ^ d ^ a) + b + x2 + 0xc4ac5665, 23); + + // round 4 + a = b + rol32((c ^ (b | ~d)) + a + x0 + 0xf4292244, 6); + d = a + rol32((b ^ (a | ~c)) + d + x7 + 0x432aff97, 10); + c = d + rol32((a ^ (d | ~b)) + c + xe + 0xab9423a7, 15); + b = c + rol32((d ^ (c | ~a)) + b + x5 + 0xfc93a039, 21); + a = b + rol32((c ^ (b | ~d)) + a + xc + 0x655b59c3, 6); + d = a + rol32((b ^ (a | ~c)) + d + x3 + 0x8f0ccc92, 10); + c = d + rol32((a ^ (d | ~b)) + c + xa + 0xffeff47d, 15); + b = c + rol32((d ^ (c | ~a)) + b + x1 + 0x85845dd1, 21); + a = b + rol32((c ^ (b | ~d)) + a + x8 + 0x6fa87e4f, 6); + d = a + rol32((b ^ (a | ~c)) + d + xf + 0xfe2ce6e0, 10); + c = d + rol32((a ^ (d | ~b)) + c + x6 + 0xa3014314, 15); + b = c + rol32((d ^ (c | ~a)) + b + xd + 0x4e0811a1, 21); + a = b + rol32((c ^ (b | ~d)) + a + x4 + 0xf7537e82, 6); + d = a + rol32((b ^ (a | ~c)) + d + xb + 0xbd3af235, 10); + c = d + rol32((a ^ (d | ~b)) + c + x2 + 0x2ad7d2bb, 15); + b = c + rol32((d ^ (c | ~a)) + b + x9 + 0xeb86d391, 21); + + this.#a = (this.#a + a) >>> 0; + this.#b = (this.#b + b) >>> 0; + this.#c = (this.#c + c) >>> 0; + this.#d = (this.#d + d) >>> 0; + } + + /** + * Update internal state + * @param data data to update, data cannot exceed 2^32 bytes + */ + update(data: Message): this { + let msg: Uint8Array; + + if (typeof data === "string") { + msg = new TextEncoder().encode(data as string); + } else if (typeof data === "object") { + if (data instanceof ArrayBuffer || ArrayBuffer.isView(data)) { + msg = new Uint8Array(data); + } else { + throw new TypeError(TYPE_ERROR_MSG); + } + } else { + throw new TypeError(TYPE_ERROR_MSG); + } + + let pos = this.#pos; + const free = BLOCK_SIZE - pos; + + if (msg.length < free) { + this.#block.set(msg, pos); + pos += msg.length; + } else { + // hash first block + this.#block.set(msg.slice(0, free), pos); + this.#hash(this.#block); + + // hash as many blocks as possible + let i = free; + while (i + BLOCK_SIZE <= msg.length) { + this.#hash(msg.slice(i, i + BLOCK_SIZE)); + i += BLOCK_SIZE; + } + + // store leftover + this.#block.fill(0).set(msg.slice(i), 0); + pos = msg.length - i; + } + + this.#pos = pos; + this.#addLength(msg.length); + + return this; + } + + /** Returns final hash */ + digest(): ArrayBuffer { + let padLen = BLOCK_SIZE - this.#pos; + if (padLen < 9) padLen += BLOCK_SIZE; + + const pad = new Uint8Array(padLen); + + pad[0] = 0x80; + + const n0 = this.#n0 << 3; + const n1 = (this.#n1 << 3) | (this.#n0 >>> 29); + pad[pad.length - 8] = n0 & 0xff; + pad[pad.length - 7] = (n0 >>> 8) & 0xff; + pad[pad.length - 6] = (n0 >>> 16) & 0xff; + pad[pad.length - 5] = (n0 >>> 24) & 0xff; + pad[pad.length - 4] = n1 & 0xff; + pad[pad.length - 3] = (n1 >>> 8) & 0xff; + pad[pad.length - 2] = (n1 >>> 16) & 0xff; + pad[pad.length - 1] = (n1 >>> 24) & 0xff; + + this.update(pad.buffer); + + const hash = new ArrayBuffer(16); + const hashView = new DataView(hash); + hashView.setUint32(0, this.#a, true); + hashView.setUint32(4, this.#b, true); + hashView.setUint32(8, this.#c, true); + hashView.setUint32(12, this.#d, true); + + return hash; + } + + /** + * Returns hash as a string of given format + * @param format format of output string (hex or base64). Default is hex + */ + toString(format: "hex" | "base64" = "hex"): string { + const hash = this.digest(); + + switch (format) { + case "hex": + return new TextDecoder().decode(hex.encode(new Uint8Array(hash))); + case "base64": { + const data = new Uint8Array(hash); + let dataString = ""; + for (let i = 0; i < data.length; ++i) { + dataString += String.fromCharCode(data[i]); + } + return btoa(dataString); + } + default: + throw new Error("md5: invalid format"); + } + } +} diff --git a/vendor/raw.githubusercontent.com/takker99/onp/0.0.1/mod.ts b/vendor/raw.githubusercontent.com/takker99/onp/0.0.1/mod.ts new file mode 100644 index 0000000..a68780a --- /dev/null +++ b/vendor/raw.githubusercontent.com/takker99/onp/0.0.1/mod.ts @@ -0,0 +1,181 @@ +/** + * The algorithm implemented here is based on "An O(NP) Sequence Comparison Algorithm" + * by described by Sun Wu, Udi Manber and Gene Myers */ + +/** LICENSE: https://github.com/cubicdaiya/onp/blob/master/COPYING */ + +type Position = { + x: number; + y: number; +}; + +export interface Added { + value: T; + type: "added"; +} +export interface Deleted { + value: T; + type: "deleted"; +} +export interface Common { + value: T; + type: "common"; +} +export type Change = Added | Deleted | Common; +export interface Replaced { + value: T; + oldValue: T; + type: "replaced"; +} +export type ExtendedChange = Change | Replaced; + +export interface DiffResult { + from: ArrayLike; + to: ArrayLike; + editDistance: number; + buildSES(): Generator, void, unknown>; +} + +export const diff = ( + left: ArrayLike, + right: ArrayLike, +): DiffResult => { + const reversed = left.length > right.length; + const a = reversed ? right : left; + const b = reversed ? left : right; + + const offset = a.length + 1; + const MAXSIZE = a.length + b.length + 3; + const path = new Array(MAXSIZE); + path.fill(-1); + const pathpos = [] as [Position, number][]; + + function snake(k: number, p: number, pp: number) { + let y = Math.max(p, pp); + let x = y - k; + + while (x < a.length && y < b.length && a[x] === b[y]) { + ++x; + ++y; + } + + path[k + offset] = pathpos.length; + pathpos.push([{ x, y }, path[k + (p > pp ? -1 : +1) + offset]]); + return y; + } + + const fp = new Array(MAXSIZE); + fp.fill(-1); + let p = -1; + const delta = b.length - a.length; + do { + ++p; + for (let k = -p; k <= delta - 1; ++k) { + fp[k + offset] = snake(k, fp[k - 1 + offset] + 1, fp[k + 1 + offset]); + } + for (let k = delta + p; k >= delta + 1; --k) { + fp[k + offset] = snake(k, fp[k - 1 + offset] + 1, fp[k + 1 + offset]); + } + fp[delta + offset] = snake( + delta, + fp[delta - 1 + offset] + 1, + fp[delta + 1 + offset], + ); + } while (fp[delta + offset] !== b.length); + + const epc = [] as Position[]; + let r = path[delta + offset]; + while (r !== -1) { + epc.push(pathpos[r][0]); + r = pathpos[r][1]; + } + + return { + from: left, + to: right, + editDistance: delta + p * 2, + buildSES: function* () { + let xIndex = 0; + let yIndex = 0; + for (const { x, y } of reverse(epc)) { + while (xIndex < x || yIndex < y) { + if (y - x > yIndex - xIndex) { + yield { value: b[yIndex], type: reversed ? "deleted" : "added" }; + ++yIndex; + } else if (y - x < yIndex - xIndex) { + yield { value: a[xIndex], type: reversed ? "added" : "deleted" }; + ++xIndex; + } else { + yield { value: a[xIndex], type: "common" }; + ++xIndex; + ++yIndex; + } + } + } + }, + }; +}; + +export function* toExtendedChanges( + changes: Iterable>, +): Generator, void, unknown> { + let addedList = [] as Added[]; + let deletedList = [] as Deleted[]; + + function* flush() { + if (addedList.length > deletedList.length) { + for (let i = 0; i < deletedList.length; i++) { + yield makeReplaced( + addedList[i], + deletedList[i], + ); + } + for (let i = deletedList.length; i < addedList.length; i++) { + yield addedList[i]; + } + } else { + for (let i = 0; i < addedList.length; i++) { + yield makeReplaced( + addedList[i], + deletedList[i], + ); + } + for (let i = addedList.length; i < deletedList.length; i++) { + yield deletedList[i]; + } + } + addedList = []; + deletedList = []; + } + + for (const change of changes) { + switch (change.type) { + case "added": + addedList.push(change); + break; + case "deleted": + deletedList.push(change); + break; + case "common": + yield* flush(); + yield change; + break; + } + } + yield* flush(); +} + +const makeReplaced = ( + left: Added, + right: Deleted, +): Replaced => ({ + value: left.value, + oldValue: right.value, + type: "replaced", +}); + +function* reverse(list: ArrayLike) { + for (let i = list.length - 1; i >= 0; i--) { + yield list[i]; + } +} diff --git a/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/mod.ts b/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/mod.ts new file mode 100644 index 0000000..8f383bb --- /dev/null +++ b/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/mod.ts @@ -0,0 +1,137 @@ +import type { Socket } from "./socket.ts"; +import { + DataOf, + EventMap, + FailedResOf, + isPageCommitError, + ListenEventMap, + Result, + SuccessResOf, + TimeoutError, + UnexpectedError, +} from "./types.ts"; +export * from "./types.ts"; +export * from "./socket.ts"; + +export interface SocketOperator { + request: ( + event: EventName, + data: DataOf, + ) => Promise< + Result< + SuccessResOf, + FailedResOf | UnexpectedError | TimeoutError + > + >; + response: ( + ...events: EventName[] + ) => AsyncGenerator; +} + +export const wrap = ( + socket: Socket, + timeout = 90000, +): SocketOperator => { + const request = ( + event: EventName, + data: DataOf, + ): Promise< + Result< + SuccessResOf, + FailedResOf | UnexpectedError | TimeoutError + > + > => { + let id: number | undefined; + return new Promise((resolve, reject) => { + const onDisconnect = (message: string) => { + clearTimeout(id); + reject(new Error(message)); + }; + socket.emit( + event, + data, + (response: { data: SuccessResOf } | { error: unknown }) => { + clearTimeout(id); + socket.off("disconnect", onDisconnect); + switch (event) { + case "socket.io-request": + if ("error" in response) { + if ( + typeof response.error === "object" && response.error && + "name" in response.error && + typeof response.error.name === "string" && + isPageCommitError({ name: response.error.name }) + ) { + resolve({ ok: false, value: response.error }); + } else { + resolve({ + ok: false, + value: { name: "UnexpectedError", value: response.error }, + }); + } + } else if ("data" in response) { + resolve({ ok: true, value: response.data }); + } + break; + case "cursor": + if ("error" in response) { + resolve({ + ok: false, + value: { name: "UnexpectedError", value: response.error }, + }); + } else if ("data" in response) { + resolve({ ok: true, value: response.data }); + } + break; + } + reject( + new Error( + 'Invalid response: missing "data" or "error" field', + ), + ); + }, + ); + id = setTimeout(() => { + socket.off("disconnect", onDisconnect); + resolve({ + ok: false, + value: { + name: "TimeoutError", + message: `Timeout: exceeded ${timeout}ms`, + }, + }); + }, timeout); + socket.once("disconnect", onDisconnect); + }); + }; + + async function* response( + ...events: EventName[] + ) { + type Data = ListenEventMap[EventName]; + let _resolve: ((data: Data) => void) | undefined; + const waitForEvent = () => new Promise((res) => _resolve = res); + const resolve = (data: Data) => { + _resolve?.(data); + }; + + for (const event of events) { + socket.on( + event, + // @ts-ignore 何故か型推論に失敗する + resolve, + ); + } + try { + while (true) { + yield await waitForEvent(); + } + } finally { + for (const event of events) { + socket.off(event, resolve); + } + } + } + + return { request, response }; +}; diff --git a/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/socket.ts b/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/socket.ts new file mode 100644 index 0000000..915b259 --- /dev/null +++ b/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/socket.ts @@ -0,0 +1,59 @@ +import type { + Manager, + ManagerOptions, + Socket, + SocketOptions, +} from "./types/socketIO/index.ts"; +export type { Manager, ManagerOptions, Socket, SocketOptions }; + +export const socketIO = async (): Promise => { + const io = await importSocketIO(); + const socket = io("https://scrapbox.io", { + reconnectionDelay: 5000, + transports: ["websocket"], + }); + + await new Promise((resolve, reject) => { + const onDisconnect = (reason: Socket.DisconnectReason) => reject(reason); + socket.once("connect", () => { + socket.off("disconnect", onDisconnect); + resolve(); + }); + socket.once("disconnect", onDisconnect); + }); + return socket; +}; + +type IO = ( + uri: string, + opts?: Partial, +) => Socket; +declare const io: IO | undefined; +const version = "4.2.0"; +const url = + `https://cdnjs.cloudflare.com/ajax/libs/socket.io/${version}/socket.io.min.js`; +let error: string | Event | undefined; + +const importSocketIO = async (): Promise => { + if (error) throw error; + if (!document.querySelector(`script[src="${url}"]`)) { + const script = document.createElement("script"); + script.src = url; + await new Promise((resolve, reject) => { + script.onload = () => resolve(); + script.onerror = (e) => { + error = e; + reject(e); + }; + document.head.append(script); + }); + } + + return new Promise((resolve) => { + const id = setInterval(() => { + if (!io) return; + clearInterval(id); + resolve(io); + }, 500); + }); +}; diff --git a/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types.ts b/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types.ts new file mode 100644 index 0000000..fed2729 --- /dev/null +++ b/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types.ts @@ -0,0 +1,289 @@ +export type JoinRoomRequest = + | JoinPageRoomRequest + | JoinProjectRoomRequest + | JoinStreamRoomRequest; + +export interface JoinProjectRoomRequest { + pageId: null; + projectId: string; + projectUpdatesStream: false; +} + +export interface JoinPageRoomRequest { + pageId: string; + projectId: string; + projectUpdatesStream: false; +} + +export interface JoinStreamRoomRequest { + pageId: null; + projectId: string; + projectUpdatesStream: true; +} + +export interface JoinRoomResponse { + success: true; + pageId: string | null; + projectId: string; +} + +export interface ProjectUpdatesStreamCommit { + kind: "page"; + id: string; + parentId: string; + projectId: string; + pageId: string; + userId: string; + changes: + | ( + | InsertChange + | UpdateChange + | DeleteChange + | TitleChange + | LinksChange + | IconsChange + )[] + | [DeletePageChange]; + cursor: null; + freeze: true; +} + +export type ProjectUpdatesStreamEvent = + | MemberJoinEvent + | InvitationResetEvent + | PageDeleteEvent + | AdminAddEvent + | AdminDeleteEvent + | OwnerSetEvent; + +export interface ProjectEvent { + id: string; + pageId: string; + userId: string; + projectId: string; + created: number; + updated: number; +} + +export interface PageDeleteEvent extends ProjectEvent { + type: "page.delete"; + data: { + titleLc: string; + }; +} + +export interface MemberJoinEvent extends ProjectEvent { + type: "member.join"; +} +export interface InvitationResetEvent extends ProjectEvent { + type: "invitation.reset"; +} +export interface AdminAddEvent extends ProjectEvent { + type: "admin.add"; + targetUserId: string; +} +export interface AdminDeleteEvent extends ProjectEvent { + type: "admin.delete"; + targetUserId: string; +} +export interface OwnerSetEvent extends ProjectEvent { + type: "owner.set"; + targetUserId: string; +} + +export interface CommitNotification extends PageCommit { + id: string; +} + +export interface PageCommit { + kind: "page"; + parentId: string; + projectId: string; + pageId: string; + userId: string; + changes: Change[] | [PinChange] | [DeletePageChange]; + cursor?: null; + freeze: true; +} +export interface PageCommitResponse { + commitId: string; +} + +export interface ErrorLike { + name: string; +} + +export interface UnexpectedError { + name: "UnexpectedError"; + value: unknown; +} +export interface TimeoutError { + name: "TimeoutError"; + message: string; +} + +export type PageCommitError = + | SocketIOError + | DuplicateTitleError + | NotFastForwardError; + +/* the error that occurs when the socket.io causes an error +* +* when this error occurs, wait for a while and retry the request +*/ +export interface SocketIOError { + name: "SocketIOError"; +} +/** the error that occurs when the title is already in use */ +export interface DuplicateTitleError { + name: "DuplicateTitleError"; +} +/** the error caused when commitId is not latest */ +export interface NotFastForwardError { + name: "NotFastForwardError"; +} + +export const isPageCommitError = (error: ErrorLike): error is PageCommitError => + pageCommitErrorNames.includes(error.name); + +const pageCommitErrorNames = [ + "SocketIOError", + "DuplicateTitleError", + "NotFastForwardError", +]; + +export type Result = + | { ok: true; value: T } + | { ok: false; value: E }; + +export interface EventMap { + "socket.io-request": ( + req: { method: "commit"; data: PageCommit } | { + method: "room:join"; + data: JoinRoomRequest; + }, + success: PageCommitResponse | JoinRoomResponse, + failed: PageCommitError, + ) => void; + cursor: ( + req: Omit, + success: undefined, + failed: unknown, + ) => void; +} +export interface ListenEventMap { + "projectUpdatesStream:commit": ProjectUpdatesStreamCommit; + "projectUpdatesStream:event": ProjectUpdatesStreamEvent; + commit: CommitNotification; + cursor: MoveCursorData; + "quick-search:commit": QuickSearchCommit; + "quick-search:replace-link": QuickSearchReplaceLink; + "infobox:updating": boolean; + "infobox:reload": void; + "literal-database:reload": void; +} + +export interface QuickSearchCommit extends Omit { + changes: + | (TitleChange | LinksChange | DescriptionsChange | ImageChange)[] + | [DeletePageChange]; +} + +export interface QuickSearchReplaceLink { + from: string; + to: string; +} + +export type DataOf = Parameters< + EventMap[Event] +>[0]; +export type SuccessResOf = Parameters< + EventMap[Event] +>[1]; +export type FailedResOf = Parameters< + EventMap[Event] +>[2]; + +export interface MoveCursorData { + user: { + id: string; + name: string; + displayName: string; + }; + pageId: string; + position: { + line: number; + char: number; + }; + visible: boolean; + socketId: string; +} + +export type Change = + | InsertChange + | UpdateChange + | DeleteChange + | LinksChange + | ProjectLinksChange + | IconsChange + | DescriptionsChange + | ImageChange + | FilesChange + | HelpFeelsChange + | infoboxDefinitionChange + | TitleChange; +export interface InsertChange { + _insert: string; + lines: { + id: string; + text: string; + }; +} +export interface UpdateChange { + _update: string; + lines: { + text: string; + }; + noTimestampUpdate?: unknown; +} +export interface DeleteChange { + _delete: string; + lines: -1; +} +export interface LinksChange { + links: string[]; +} +export interface ProjectLinksChange { + projectLinks: string[]; +} +export interface IconsChange { + icons: string[]; +} +export interface DescriptionsChange { + descriptions: string[]; +} +export interface ImageChange { + image: string | null; +} +export interface TitleChange { + title: string; +} +export interface FilesChange { + /** file id */ + files: string[]; +} +export interface HelpFeelsChange { + /** Helpfeel記法の先頭の`? `をとったもの */ + helpfeels: string[]; +} +export interface infoboxDefinitionChange { + /** `table:infobox`または`table:cosense`の各行をtrimしたもの */ + infoboxDefinition: string[]; +} +export interface PinChange { + pin: number; +} +export interface DeletePageChange { + deleted: true; + merged?: true; +} diff --git a/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/emitter.ts b/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/emitter.ts new file mode 100644 index 0000000..bb7aa7d --- /dev/null +++ b/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/emitter.ts @@ -0,0 +1,24 @@ +// this file is based on https://cdn.esm.sh/v54/@types/component-emitter@1.2.10/index.d.ts +// Type definitions for component-emitter v1.2.1 +// Project: https://www.npmjs.com/package/component-emitter +// Definitions by: Peter Snider +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +// TypeScript Version: 2.2 + +// deno-lint-ignore-file ban-types no-explicit-any +interface Emitter { + on(event: Event, listener: Function): Emitter; + once(event: Event, listener: Function): Emitter; + off(event?: Event, listener?: Function): Emitter; + emit(event: Event, ...args: any[]): Emitter; + listeners(event: Event): Function[]; + hasListeners(event: Event): boolean; +} + +declare const Emitter: { + (obj?: object): Emitter; + new (obj?: object): Emitter; +}; + +export { Emitter }; diff --git a/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/index.ts b/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/index.ts new file mode 100644 index 0000000..c12b106 --- /dev/null +++ b/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/index.ts @@ -0,0 +1,39 @@ +// this file is copied from https://cdn.esm.sh/v54/socket.io-client@4.2.0/build/index.d.ts +import { ManagerOptions } from "./manager.ts"; +import { Socket, SocketOptions } from "./socket.ts"; +/** + * Looks up an existing `Manager` for multiplexing. + * If the user summons: + * + * `io('http://localhost/a');` + * `io('http://localhost/b');` + * + * We reuse the existing instance based on same scheme/port/host, + * and we initialize sockets for each namespace. + * + * @public + */ +declare function lookup(opts?: Partial): Socket; +declare function lookup( + uri: string, + opts?: Partial, +): Socket; +declare function lookup( + uri: string | Partial, + opts?: Partial, +): Socket; +/** + * Protocol version. + * + * @public + */ +export { protocol } from "./parser.ts"; +/** + * Expose constructors for standalone build. + * + * @public + */ +export type { Manager, ManagerOptions } from "./manager.ts"; +export { Socket } from "./socket.ts"; +export type { lookup as io, SocketOptions }; +export default lookup; diff --git a/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/manager.ts b/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/manager.ts new file mode 100644 index 0000000..5270161 --- /dev/null +++ b/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/manager.ts @@ -0,0 +1,486 @@ +// this file is copied from https://cdn.esm.sh/v54/socket.io-client@4.2.0/build/manager.d.ts +// deno-lint-ignore-file no-explicit-any camelcase ban-types +import { Socket, SocketOptions } from "./socket.ts"; +import { Packet } from "./parser.ts"; +import { + DefaultEventsMap, + EventsMap, + StrictEventEmitter, +} from "./typed-events.ts"; +interface EngineOptions { + /** + * The host that we're connecting to. Set from the URI passed when connecting + */ + host: string; + /** + * The hostname for our connection. Set from the URI passed when connecting + */ + hostname: string; + /** + * If this is a secure connection. Set from the URI passed when connecting + */ + secure: boolean; + /** + * The port for our connection. Set from the URI passed when connecting + */ + port: string; + /** + * Any query parameters in our uri. Set from the URI passed when connecting + */ + query: { + [key: string]: string; + }; + /** + * `http.Agent` to use, defaults to `false` (NodeJS only) + */ + agent: string | boolean; + /** + * Whether the client should try to upgrade the transport from + * long-polling to something better. + * @default true + */ + upgrade: boolean; + /** + * Forces JSONP for polling transport. + */ + forceJSONP: boolean; + /** + * Determines whether to use JSONP when necessary for polling. If + * disabled (by settings to false) an error will be emitted (saying + * "No transports available") if no other transports are available. + * If another transport is available for opening a connection (e.g. + * WebSocket) that transport will be used instead. + * @default true + */ + jsonp: boolean; + /** + * Forces base 64 encoding for polling transport even when XHR2 + * responseType is available and WebSocket even if the used standard + * supports binary. + */ + forceBase64: boolean; + /** + * Enables XDomainRequest for IE8 to avoid loading bar flashing with + * click sound. default to `false` because XDomainRequest has a flaw + * of not sending cookie. + * @default false + */ + enablesXDR: boolean; + /** + * The param name to use as our timestamp key + * @default 't' + */ + timestampParam: string; + /** + * Whether to add the timestamp with each transport request. Note: this + * is ignored if the browser is IE or Android, in which case requests + * are always stamped + * @default false + */ + timestampRequests: boolean; + /** + * A list of transports to try (in order). Engine.io always attempts to + * connect directly with the first one, provided the feature detection test + * for it passes. + * @default ['polling','websocket'] + */ + transports: string[]; + /** + * The port the policy server listens on + * @default 843 + */ + policyPost: number; + /** + * If true and if the previous websocket connection to the server succeeded, + * the connection attempt will bypass the normal upgrade process and will + * initially try websocket. A connection attempt following a transport error + * will use the normal upgrade process. It is recommended you turn this on + * only when using SSL/TLS connections, or if you know that your network does + * not block websockets. + * @default false + */ + rememberUpgrade: boolean; + /** + * Are we only interested in transports that support binary? + */ + onlyBinaryUpgrades: boolean; + /** + * Timeout for xhr-polling requests in milliseconds (0) (only for polling transport) + */ + requestTimeout: number; + /** + * Transport options for Node.js client (headers etc) + */ + transportOptions: Object; + /** + * (SSL) Certificate, Private key and CA certificates to use for SSL. + * Can be used in Node.js client environment to manually specify + * certificate information. + */ + pfx: string; + /** + * (SSL) Private key to use for SSL. Can be used in Node.js client + * environment to manually specify certificate information. + */ + key: string; + /** + * (SSL) A string or passphrase for the private key or pfx. Can be + * used in Node.js client environment to manually specify certificate + * information. + */ + passphrase: string; + /** + * (SSL) Public x509 certificate to use. Can be used in Node.js client + * environment to manually specify certificate information. + */ + cert: string; + /** + * (SSL) An authority certificate or array of authority certificates to + * check the remote host against.. Can be used in Node.js client + * environment to manually specify certificate information. + */ + ca: string | string[]; + /** + * (SSL) A string describing the ciphers to use or exclude. Consult the + * [cipher format list] + * (http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT) for + * details on the format.. Can be used in Node.js client environment to + * manually specify certificate information. + */ + ciphers: string; + /** + * (SSL) If true, the server certificate is verified against the list of + * supplied CAs. An 'error' event is emitted if verification fails. + * Verification happens at the connection level, before the HTTP request + * is sent. Can be used in Node.js client environment to manually specify + * certificate information. + */ + rejectUnauthorized: boolean; + /** + * Headers that will be passed for each request to the server (via xhr-polling and via websockets). + * These values then can be used during handshake or for special proxies. + */ + extraHeaders?: { + [header: string]: string; + }; + /** + * Whether to include credentials (cookies, authorization headers, TLS + * client certificates, etc.) with cross-origin XHR polling requests + * @default false + */ + withCredentials: boolean; + /** + * Whether to automatically close the connection whenever the beforeunload event is received. + * @default true + */ + closeOnBeforeunload: boolean; + /** + * Whether to always use the native timeouts. This allows the client to + * reconnect when the native timeout functions are overridden, such as when + * mock clocks are installed. + * @default false + */ + useNativeTimers: boolean; +} +export interface ManagerOptions extends EngineOptions { + /** + * Should we force a new Manager for this connection? + * @default false + */ + forceNew: boolean; + /** + * Should we multiplex our connection (reuse existing Manager) ? + * @default true + */ + multiplex: boolean; + /** + * The path to get our client file from, in the case of the server + * serving it + * @default '/socket.io' + */ + path: string; + /** + * Should we allow reconnections? + * @default true + */ + reconnection: boolean; + /** + * How many reconnection attempts should we try? + * @default Infinity + */ + reconnectionAttempts: number; + /** + * The time delay in milliseconds between reconnection attempts + * @default 1000 + */ + reconnectionDelay: number; + /** + * The max time delay in milliseconds between reconnection attempts + * @default 5000 + */ + reconnectionDelayMax: number; + /** + * Used in the exponential backoff jitter when reconnecting + * @default 0.5 + */ + randomizationFactor: number; + /** + * The timeout in milliseconds for our connection attempt + * @default 20000 + */ + timeout: number; + /** + * Should we automatically connect? + * @default true + */ + autoConnect: boolean; + /** + * weather we should unref the reconnect timer when it is + * create automatically + * @default false + */ + autoUnref: boolean; + /** + * the parser to use. Defaults to an instance of the Parser that ships with socket.io. + */ + parser: any; +} +interface ManagerReservedEvents { + open: () => void; + error: (err: Error) => void; + ping: () => void; + packet: (packet: Packet) => void; + close: (reason: string) => void; + reconnect_failed: () => void; + reconnect_attempt: (attempt: number) => void; + reconnect_error: (err: Error) => void; + reconnect: (attempt: number) => void; +} +export declare class Manager< + ListenEvents extends EventsMap = DefaultEventsMap, + EmitEvents extends EventsMap = ListenEvents, +> extends StrictEventEmitter<{}, {}, ManagerReservedEvents> { + /** + * The Engine.IO client instance + * + * @public + */ + engine: any; + /** + * @private + */ + _autoConnect: boolean; + /** + * @private + */ + _readyState: "opening" | "open" | "closed"; + /** + * @private + */ + _reconnecting: boolean; + private readonly uri; + opts: Partial; + private nsps; + private subs; + private backoff; + private setTimeoutFn; + private _reconnection; + private _reconnectionAttempts; + private _reconnectionDelay; + private _randomizationFactor; + private _reconnectionDelayMax; + private _timeout; + private encoder; + private decoder; + private skipReconnect; + /** + * `Manager` constructor. + * + * @param uri - engine instance or engine uri/opts + * @param opts - options + * @public + */ + constructor(opts: Partial); + constructor(uri?: string, opts?: Partial); + constructor( + uri?: string | Partial, + opts?: Partial, + ); + /** + * Sets the `reconnection` config. + * + * @param {Boolean} v - true/false if it should automatically reconnect + * @return {Manager} self or value + * @public + */ + reconnection(v: boolean): this; + reconnection(): boolean; + reconnection(v?: boolean): this | boolean; + /** + * Sets the reconnection attempts config. + * + * @param {Number} v - max reconnection attempts before giving up + * @return {Manager} self or value + * @public + */ + reconnectionAttempts(v: number): this; + reconnectionAttempts(): number; + reconnectionAttempts(v?: number): this | number; + /** + * Sets the delay between reconnections. + * + * @param {Number} v - delay + * @return {Manager} self or value + * @public + */ + reconnectionDelay(v: number): this; + reconnectionDelay(): number; + reconnectionDelay(v?: number): this | number; + /** + * Sets the randomization factor + * + * @param v - the randomization factor + * @return self or value + * @public + */ + randomizationFactor(v: number): this; + randomizationFactor(): number; + randomizationFactor(v?: number): this | number; + /** + * Sets the maximum delay between reconnections. + * + * @param v - delay + * @return self or value + * @public + */ + reconnectionDelayMax(v: number): this; + reconnectionDelayMax(): number; + reconnectionDelayMax(v?: number): this | number; + /** + * Sets the connection timeout. `false` to disable + * + * @param v - connection timeout + * @return self or value + * @public + */ + timeout(v: number | boolean): this; + timeout(): number | boolean; + timeout(v?: number | boolean): this | number | boolean; + /** + * Starts trying to reconnect if reconnection is enabled and we have not + * started reconnecting yet + * + * @private + */ + private maybeReconnectOnOpen; + /** + * Sets the current transport `socket`. + * + * @param {Function} fn - optional, callback + * @return self + * @public + */ + open(fn?: (err?: Error) => void): this; + /** + * Alias for open() + * + * @return self + * @public + */ + connect(fn?: (err?: Error) => void): this; + /** + * Called upon transport open. + * + * @private + */ + private onopen; + /** + * Called upon a ping. + * + * @private + */ + private onping; + /** + * Called with data. + * + * @private + */ + private ondata; + /** + * Called when parser fully decodes a packet. + * + * @private + */ + private ondecoded; + /** + * Called upon socket error. + * + * @private + */ + private onerror; + /** + * Creates a new socket for the given `nsp`. + * + * @return {Socket} + * @public + */ + socket(nsp: string, opts?: Partial): Socket; + /** + * Called upon a socket close. + * + * @param socket + * @private + */ + _destroy(socket: Socket): void; + /** + * Writes a packet. + * + * @param packet + * @private + */ + _packet( + packet: Partial< + Packet & { + query: string; + options: any; + } + >, + ): void; + /** + * Clean up transport subscriptions and packet buffer. + * + * @private + */ + private cleanup; + /** + * Close the current socket. + * + * @private + */ + _close(): void; + /** + * Alias for close() + * + * @private + */ + private disconnect; + /** + * Called upon engine close. + * + * @private + */ + private onclose; + /** + * Attempt a reconnection. + * + * @private + */ + private reconnect; + /** + * Called upon successful reconnect. + * + * @private + */ + private onreconnect; +} +export {}; diff --git a/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/parser.ts b/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/parser.ts new file mode 100644 index 0000000..e2409e4 --- /dev/null +++ b/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/parser.ts @@ -0,0 +1,75 @@ +// this file is copied from https://cdn.esm.sh/v54/socket.io-parser@4.0.4/dist/index.d.ts + +// deno-lint-ignore-file no-explicit-any +import { Emitter } from "./emitter.ts"; +/** + * Protocol version. + * + * @public + */ +export declare const protocol: number; +export declare enum PacketType { + CONNECT = 0, + DISCONNECT = 1, + EVENT = 2, + ACK = 3, + CONNECT_ERROR = 4, + BINARY_EVENT = 5, + BINARY_ACK = 6, +} +export interface Packet { + type: PacketType; + nsp: string; + data?: any; + id?: number; + attachments?: number; +} +/** + * A socket.io Encoder instance + */ +export declare class Encoder { + /** + * Encode a packet as a single string if non-binary, or as a + * buffer sequence, depending on packet type. + * + * @param {Object} obj - packet object + */ + encode(obj: Packet): any[]; + /** + * Encode packet as string. + */ + private encodeAsString; + /** + * Encode packet as 'buffer sequence' by removing blobs, and + * deconstructing packet into object with placeholders and + * a list of buffers. + */ + private encodeAsBinary; +} +/** + * A socket.io Decoder instance + * + * @return {Object} decoder + */ +export declare class Decoder extends Emitter { + private reconstructor; + constructor(); + /** + * Decodes an encoded packet string into packet JSON. + * + * @param {String} obj - encoded packet + */ + add(obj: any): void; + /** + * Decode a packet String (JSON data) + * + * @param {String} str + * @return {Object} packet + */ + private decodeString; + private static isPayloadValid; + /** + * Deallocates a parser's resources + */ + destroy(): void; +} diff --git a/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/socket.ts b/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/socket.ts new file mode 100644 index 0000000..3342860 --- /dev/null +++ b/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/socket.ts @@ -0,0 +1,238 @@ +// deno-lint-ignore-file no-explicit-any camelcase +// this file is copied from https://cdn.esm.sh/v54/socket.io-client@4.2.0/build/socket.d.ts +import { Packet } from "./parser.ts"; +import { Manager } from "./manager.ts"; +import { + DefaultEventsMap, + EventNames, + EventParams, + EventsMap, + StrictEventEmitter, +} from "./typed-events.ts"; +export interface SocketOptions { + /** + * the authentication payload sent when connecting to the Namespace + */ + auth: { + [key: string]: any; + } | ((cb: (data: object) => void) => void); +} +interface SocketReservedEvents { + connect: () => void; + connect_error: (err: Error) => void; + disconnect: (reason: Socket.DisconnectReason) => void; +} +export declare class Socket< + ListenEvents extends EventsMap = DefaultEventsMap, + EmitEvents extends EventsMap = ListenEvents, +> extends StrictEventEmitter { + readonly io: Manager; + id: string; + connected: boolean; + disconnected: boolean; + auth: { + [key: string]: any; + } | ((cb: (data: object) => void) => void); + receiveBuffer: Array>; + sendBuffer: Array; + private readonly nsp; + private ids; + private acks; + private flags; + private subs?; + private _anyListeners; + /** + * `Socket` constructor. + * + * @public + */ + constructor(io: Manager, nsp: string, opts?: Partial); + /** + * Subscribe to open, close and packet events + * + * @private + */ + private subEvents; + /** + * Whether the Socket will try to reconnect when its Manager connects or reconnects + */ + get active(): boolean; + /** + * "Opens" the socket. + * + * @public + */ + connect(): this; + /** + * Alias for connect() + */ + open(): this; + /** + * Sends a `message` event. + * + * @return self + * @public + */ + send(...args: any[]): this; + /** + * Override `emit`. + * If the event is in `events`, it's emitted normally. + * + * @return self + * @public + */ + emit>( + ev: Ev, + ...args: EventParams + ): this; + /** + * Sends a packet. + * + * @param packet + * @private + */ + private packet; + /** + * Called upon engine `open`. + * + * @private + */ + private onopen; + /** + * Called upon engine or manager `error`. + * + * @param err + * @private + */ + private onerror; + /** + * Called upon engine `close`. + * + * @param reason + * @private + */ + private onclose; + /** + * Called with socket packet. + * + * @param packet + * @private + */ + private onpacket; + /** + * Called upon a server event. + * + * @param packet + * @private + */ + private onevent; + private emitEvent; + /** + * Produces an ack callback to emit with an event. + * + * @private + */ + private ack; + /** + * Called upon a server acknowlegement. + * + * @param packet + * @private + */ + private onack; + /** + * Called upon server connect. + * + * @private + */ + private onconnect; + /** + * Emit buffered events (received and emitted). + * + * @private + */ + private emitBuffered; + /** + * Called upon server disconnect. + * + * @private + */ + private ondisconnect; + /** + * Called upon forced client/server side disconnections, + * this method ensures the manager stops tracking us and + * that reconnections don't get triggered for this. + * + * @private + */ + private destroy; + /** + * Disconnects the socket manually. + * + * @return self + * @public + */ + disconnect(): this; + /** + * Alias for disconnect() + * + * @return self + * @public + */ + close(): this; + /** + * Sets the compress flag. + * + * @param compress - if `true`, compresses the sending data + * @return self + * @public + */ + compress(compress: boolean): this; + /** + * Sets a modifier for a subsequent event emission that the event message will be dropped when this socket is not + * ready to send messages. + * + * @returns self + * @public + */ + get volatile(): this; + /** + * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the + * callback. + * + * @param listener + * @public + */ + onAny(listener: (...args: any[]) => void): this; + /** + * Adds a listener that will be fired when any event is emitted. The event name is passed as the first argument to the + * callback. The listener is added to the beginning of the listeners array. + * + * @param listener + * @public + */ + prependAny(listener: (...args: any[]) => void): this; + /** + * Removes the listener that will be fired when any event is emitted. + * + * @param listener + * @public + */ + offAny(listener?: (...args: any[]) => void): this; + /** + * Returns an array of listeners that are listening for any event that is specified. This array can be manipulated, + * e.g. to remove listeners. + * + * @public + */ + listenersAny(): ((...args: any[]) => void)[]; +} +export declare namespace Socket { + type DisconnectReason = + | "io server disconnect" + | "io client disconnect" + | "ping timeout" + | "transport close" + | "transport error"; +} +export {}; diff --git a/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/typed-events.ts b/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/typed-events.ts new file mode 100644 index 0000000..b440c79 --- /dev/null +++ b/vendor/raw.githubusercontent.com/takker99/scrapbox-userscript-websocket/0.2.4/types/socketIO/typed-events.ts @@ -0,0 +1,129 @@ +// this file is copied from https://cdn.esm.sh/v54/socket.io-client@4.2.0/build/typed-events.d.ts +// deno-lint-ignore-file no-explicit-any ban-types +import { Emitter } from "./emitter.ts"; +/** + * An events map is an interface that maps event names to their value, which + * represents the type of the `on` listener. + */ +export interface EventsMap { + [event: string]: any; +} +/** + * The default events map, used if no EventsMap is given. Using this EventsMap + * is equivalent to accepting all event names, and any data. + */ +export interface DefaultEventsMap { + [event: string]: (...args: any[]) => void; +} +/** + * Returns a union type containing all the keys of an event map. + */ +export declare type EventNames = + & keyof Map + & (string | symbol); +/** The tuple type representing the parameters of an event listener */ +export declare type EventParams< + Map extends EventsMap, + Ev extends EventNames, +> = Parameters; +/** + * The event names that are either in ReservedEvents or in UserEvents + */ +export declare type ReservedOrUserEventNames< + ReservedEventsMap extends EventsMap, + UserEvents extends EventsMap, +> = EventNames | EventNames; +/** + * Type of a listener of a user event or a reserved event. If `Ev` is in + * `ReservedEvents`, the reserved event listener is returned. + */ +export declare type ReservedOrUserListener< + ReservedEvents extends EventsMap, + UserEvents extends EventsMap, + Ev extends ReservedOrUserEventNames, +> = FallbackToUntypedListener< + Ev extends EventNames ? ReservedEvents[Ev] + : Ev extends EventNames ? UserEvents[Ev] + : never +>; +/** + * Returns an untyped listener type if `T` is `never`; otherwise, returns `T`. + * + * This is a hack to mitigate https://github.com/socketio/socket.io/issues/3833. + * Needed because of https://github.com/microsoft/TypeScript/issues/41778 + */ +declare type FallbackToUntypedListener = [T] extends [never] + ? (...args: any[]) => void | Promise + : T; +/** + * Strictly typed version of an `EventEmitter`. A `TypedEventEmitter` takes type + * parameters for mappings of event names to event data types, and strictly + * types method calls to the `EventEmitter` according to these event maps. + * + * @typeParam ListenEvents - `EventsMap` of user-defined events that can be + * listened to with `on` or `once` + * @typeParam EmitEvents - `EventsMap` of user-defined events that can be + * emitted with `emit` + * @typeParam ReservedEvents - `EventsMap` of reserved events, that can be + * emitted by socket.io with `emitReserved`, and can be listened to with + * `listen`. + */ +export declare abstract class StrictEventEmitter< + ListenEvents extends EventsMap, + EmitEvents extends EventsMap, + ReservedEvents extends EventsMap = {}, +> extends Emitter { + /** + * Adds the `listener` function as an event listener for `ev`. + * + * @param ev Name of the event + * @param listener Callback function + */ + on>( + ev: Ev, + listener: ReservedOrUserListener, + ): this; + /** + * Adds a one-time `listener` function as an event listener for `ev`. + * + * @param ev Name of the event + * @param listener Callback function + */ + once>( + ev: Ev, + listener: ReservedOrUserListener, + ): this; + /** + * Emits an event. + * + * @param ev Name of the event + * @param args Values to send to listeners of this event + */ + emit>( + ev: Ev, + ...args: EventParams + ): this; + /** + * Emits a reserved event. + * + * This method is `protected`, so that only a class extending + * `StrictEventEmitter` can emit its own reserved events. + * + * @param ev Reserved event name + * @param args Arguments to emit along with the event + */ + protected emitReserved>( + ev: Ev, + ...args: EventParams + ): this; + /** + * Returns the listeners listening to an event. + * + * @param event Event name + * @returns Array of listeners subscribed to `event` + */ + listeners>( + event: Ev, + ): ReservedOrUserListener[]; +} +export {};