diff --git a/package-lock.json b/package-lock.json index 1f6ab9d8..35a479d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,11 +17,13 @@ "dompurify": "^3.4.4", "folder-pane": "4.1.5-0", "issue-pane": "4.1.1-0", + "lit": "^3.3.3", "lit-html": "^3.3.2", - "marked": "^18.0.3", + "markdown-it": "^15.0.3", "meeting-pane": "4.1.1-0", "mime-types": "^3.0.2", "pane-registry": "5.1.2-0", + "pdfjs-dist": "^6.5.438", "profile-pane": "4.1.1-0", "rdflib": "2.4.1", "solid-logic": "6.2.1-0", @@ -33,9 +35,11 @@ "@iconify/json": "2.2.494", "@testing-library/dom": "^10.4.1", "@testing-library/jest-dom": "^6.9.1", + "@types/markdown-it": "^14.2.0", "@types/node": "^22.20.0", "@typescript-eslint/parser": "^8.59.3", "@vitest/coverage-v8": "^4.0.18", + "axe-core": "^4.14.1", "eslint": "^9.39.4", "globals": "^17.6.0", "jsdom": "^28.1.0", @@ -44,7 +48,8 @@ "typescript": "^6.0.3", "unplugin-icons": "^23.0.1", "vite": "^8.0.16", - "vitest": "^4.0.18" + "vitest": "^4.0.18", + "vitest-axe": "^0.1.0" } }, "node_modules/@acemir/cssom": { @@ -148,18 +153,6 @@ "node": ">=14.17.0" } }, - "node_modules/@awesome.me/webawesome/node_modules/marked": { - "version": "11.2.0", - "resolved": "https://registry.npmjs.org/marked/-/marked-11.2.0.tgz", - "integrity": "sha512-HR0m3bvu0jAPYiIvLUUQtdg1g6D247//lvcekpHO1WMvbwDlwSkZAX9Lw4F4YHE1T0HaaNve0tuAWuV1UJ6vtw==", - "license": "MIT", - "bin": { - "marked": "bin/marked.js" - }, - "engines": { - "node": ">= 18" - } - }, "node_modules/@babel/code-frame": { "version": "7.29.7", "resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.29.7.tgz", @@ -1971,9 +1964,9 @@ } }, "node_modules/@codemirror/commands": { - "version": "6.11.1", - "resolved": "https://registry.npmjs.org/@codemirror/commands/-/commands-6.11.1.tgz", - "integrity": "sha512-O/4hG3SC1YwcmQ0d2UVNDs+AsaNWd1iHVxbTeEBuqH+6bExAiPK3iS/BvpY6rZGURALv4ZD3sIgcCmRvw3ehBg==", + "version": "6.11.2", + "resolved": "https://registry.npmjs.org/@codemirror/commands/-/commands-6.11.2.tgz", + "integrity": "sha512-NbH6Q9lmcXvf9s5/mMJIwL2Hjl2NEdsN/dDlezGnaFOQgNZ59dT7ndKUf21/PIjJacD/Ti2Ifi4TsBkO6WHvsg==", "license": "MIT", "dependencies": { "@codemirror/language": "^6.0.0", @@ -2117,9 +2110,9 @@ "license": "MIT" }, "node_modules/@codemirror/view": { - "version": "6.43.15", - "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.43.15.tgz", - "integrity": "sha512-HHsfpqFeHyXLs983pSRe38Xajs0vFWZQ2BuX0m7Ki8w3jZ5iD8cuR3lBz2/5/X53Dhf32SBHKh6rtSTB6tKeGw==", + "version": "6.44.0", + "resolved": "https://registry.npmjs.org/@codemirror/view/-/view-6.44.0.tgz", + "integrity": "sha512-kAUekx35l9u64jW/NzdO054l80lz+ri+Z5ZFS+dMpMrCbG5pFiTz58twWcWghzBEInWno0SPaURNSCnHHvipnQ==", "license": "MIT", "dependencies": { "@codemirror/state": "^6.7.0", @@ -2863,9 +2856,9 @@ "license": "MIT" }, "node_modules/@lezer/common": { - "version": "1.5.6", - "resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.5.6.tgz", - "integrity": "sha512-NZxu3q49ck+YYbEJPuIPIyFP37XneBvzPIarBHEXBLBVfkZqQieZ/Y2boYnGNYtmjpOZLnAKs/lwqtmDpi365w==", + "version": "1.5.7", + "resolved": "https://registry.npmjs.org/@lezer/common/-/common-1.5.7.tgz", + "integrity": "sha512-3+3PN+M/3xSjrlQz8/wBPOl+JYGJ+G37ZszHfnhphFwj41qPUPxsz4WEic3ZyVpL23rX1qefaGqz0lA7jGUqwg==", "license": "MIT" }, "node_modules/@lezer/css": { @@ -2900,9 +2893,9 @@ } }, "node_modules/@lezer/javascript": { - "version": "1.5.6", - "resolved": "https://registry.npmjs.org/@lezer/javascript/-/javascript-1.5.6.tgz", - "integrity": "sha512-sEvOqpl4vJQca0NugSQK02vQPbc5KrvoojnYGoqqFgFO0MtcYhwGiHKVEB+LuXYJnfyXo4QPA8ztbrEa4Fw5NA==", + "version": "1.5.7", + "resolved": "https://registry.npmjs.org/@lezer/javascript/-/javascript-1.5.7.tgz", + "integrity": "sha512-o3Rn+TzKuN25sdILOZFXi8hz4K/ed4OK0I+QrAi7Zzn3tXRBZmfsQrZpLX47ZYK/rZU8Vu4jLkz4SOSYRzBfjw==", "license": "MIT", "dependencies": { "@lezer/common": "^1.2.0", @@ -2922,18 +2915,18 @@ } }, "node_modules/@lezer/lr": { - "version": "1.4.12", - "resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.4.12.tgz", - "integrity": "sha512-On9HU4oMMiHPMkQDgoTnGahjgG5n/MkN38CgG77sMraKLL+3JBbeQNi1FcCXV9QRqwF9/BUXP3caHyJC1fBOTQ==", + "version": "1.4.13", + "resolved": "https://registry.npmjs.org/@lezer/lr/-/lr-1.4.13.tgz", + "integrity": "sha512-Ez6qF9rXdnR/7hTcA6kHq1uTcPV+17hyUFjiHBVYNi0a81TgbkC0SwiNvxcuUMkvX7phuhTHo+QAXh9L2kjGdg==", "license": "MIT", "dependencies": { "@lezer/common": "^1.0.0" } }, "node_modules/@lezer/markdown": { - "version": "1.8.1", - "resolved": "https://registry.npmjs.org/@lezer/markdown/-/markdown-1.8.1.tgz", - "integrity": "sha512-M5YmEcKWO4mJ45Y1hECwqyu8cLv25EiXOK554PVOvDOWOP0olwelHHQUWr9sjF+d1bENVhy0nfJ8E57XZUTiXg==", + "version": "1.8.2", + "resolved": "https://registry.npmjs.org/@lezer/markdown/-/markdown-1.8.2.tgz", + "integrity": "sha512-q0kGuKOFrKEMi8d3ExryIOAT5XwjW86x1JO5scQB7gcXr8LobgXP3l6Gq6ArpXUQLeDju9cwRHF2Axjk6VMhLQ==", "license": "MIT", "dependencies": { "@lezer/common": "^1.5.0", @@ -3081,6 +3074,271 @@ "integrity": "sha512-Wy0V7+SGUjnF9/TkiM1hKVDPj7jKXduPNboMVtHTA8dySMURWqfg/JZ9E2Sq8JgSJmkl7k7Qe9FLeMSrSraWmQ==", "license": "MIT" }, + "node_modules/@napi-rs/canvas": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas/-/canvas-1.2.1.tgz", + "integrity": "sha512-dTFJYKi4eE9Yr9FlLi7hN/Q+15VVmpnA1HrKkTzGQuWiVw5MWBL2reLXAaXUMENmzKxtlqYCtCp1NIeQqx+uEA==", + "license": "MIT", + "optional": true, + "workspaces": [ + "e2e/*" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + }, + "optionalDependencies": { + "@napi-rs/canvas-android-arm64": "1.2.1", + "@napi-rs/canvas-darwin-arm64": "1.2.1", + "@napi-rs/canvas-darwin-x64": "1.2.1", + "@napi-rs/canvas-linux-arm-gnueabihf": "1.2.1", + "@napi-rs/canvas-linux-arm64-gnu": "1.2.1", + "@napi-rs/canvas-linux-arm64-musl": "1.2.1", + "@napi-rs/canvas-linux-riscv64-gnu": "1.2.1", + "@napi-rs/canvas-linux-x64-gnu": "1.2.1", + "@napi-rs/canvas-linux-x64-musl": "1.2.1", + "@napi-rs/canvas-win32-arm64-msvc": "1.2.1", + "@napi-rs/canvas-win32-x64-msvc": "1.2.1" + } + }, + "node_modules/@napi-rs/canvas-android-arm64": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-android-arm64/-/canvas-android-arm64-1.2.1.tgz", + "integrity": "sha512-CtM+0Xieqc8jMyIm6sPLbnvDut4/BmSAP+HQnbbwPcw3ZG+bY1NhwndtpOzAPcNbIPyWuiShSF99/Ja7vYeXbw==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "android" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-darwin-arm64": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-darwin-arm64/-/canvas-darwin-arm64-1.2.1.tgz", + "integrity": "sha512-DazlaWwTa1xIdROpA8e95ttU4yNedl6brXbqBm+upoQ/1WIpmDu4zwanYp6ftGIbrjMld/OjJK15kFrDPWLoEQ==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-darwin-x64": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-darwin-x64/-/canvas-darwin-x64-1.2.1.tgz", + "integrity": "sha512-XU9zFjeRusfeP49/Dk4CNqvMzxOiBtrl6Qoyndp2Wxk0LhJxgiUhhSMGLIripipZZKfKJOo1h/k8FswMVk0PuA==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-linux-arm-gnueabihf": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm-gnueabihf/-/canvas-linux-arm-gnueabihf-1.2.1.tgz", + "integrity": "sha512-24R1MI8ZcWSrqU5rD+hRelWsoExMc4Bo8vRbIIge4f5X97P4pvrPMIMV0e5szSyU9y5aF8gA+CCXwWWRwFthYg==", + "cpu": [ + "arm" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-linux-arm64-gnu": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm64-gnu/-/canvas-linux-arm64-gnu-1.2.1.tgz", + "integrity": "sha512-2pxxAlQ3wTYxqZnuqXhQbE4sTvLC1/dYkuPpudggCgvQXRb6KYm6K01UAL2kWqpkTqFmy6kHfIjLJ/86vQhOnQ==", + "cpu": [ + "arm64" + ], + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-linux-arm64-musl": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-arm64-musl/-/canvas-linux-arm64-musl-1.2.1.tgz", + "integrity": "sha512-+Ksk8ilbmbA4oMu+BfOL/WZMeDY0Z40TblthqS8Ssr6K7MFXh9707O1H3uJcVx3H7plXWsDuycGai20FBRO0sg==", + "cpu": [ + "arm64" + ], + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-linux-riscv64-gnu": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-riscv64-gnu/-/canvas-linux-riscv64-gnu-1.2.1.tgz", + "integrity": "sha512-B7Y0cljUn/kTmDiSJ7q94axEvQMJLoJZX8FDf8+JdvAkQiUR2tHnDomGIxtHsvXGmzf3UE736YdtvNLEfCDjdg==", + "cpu": [ + "riscv64" + ], + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-linux-x64-gnu": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-x64-gnu/-/canvas-linux-x64-gnu-1.2.1.tgz", + "integrity": "sha512-1/7y8Yx589PcQE8Xuvc0ZLRwEsjA1FonfV+ZWUS4s+pwI6Aa5i+VHUhAv+pR1692A+mIjuaH5FpH89+CFK0Nng==", + "cpu": [ + "x64" + ], + "libc": [ + "glibc" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-linux-x64-musl": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-linux-x64-musl/-/canvas-linux-x64-musl-1.2.1.tgz", + "integrity": "sha512-fiO90vFdt9Kq3v+sPHSczzbpRi2CTMx6NQdfD31zfJFeouXVR8EeiGyHpXuV5wwE6ui7IQLmVTHq7Uz3V0xq/w==", + "cpu": [ + "x64" + ], + "libc": [ + "musl" + ], + "license": "MIT", + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-win32-arm64-msvc": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-win32-arm64-msvc/-/canvas-win32-arm64-msvc-1.2.1.tgz", + "integrity": "sha512-COZrzxhGGpWwP+3xMtppDz3J7ycLKsIZfClKxAmJRZFR5sVmiujy+ShnMyzmQtzTzpFInxkzQ35maAxYjR88kA==", + "cpu": [ + "arm64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, + "node_modules/@napi-rs/canvas-win32-x64-msvc": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/@napi-rs/canvas-win32-x64-msvc/-/canvas-win32-x64-msvc-1.2.1.tgz", + "integrity": "sha512-oPzPLrFlox/NAcqVVT8mHaXF0FsQ2XXX3nWy/l5yV/NksxBf9V/nnCes+O5fz+xzzwDNVjL5EOk7+siz5HmfCA==", + "cpu": [ + "x64" + ], + "license": "MIT", + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">= 10" + }, + "funding": { + "type": "github", + "url": "https://github.com/sponsors/Brooooooklyn" + } + }, "node_modules/@napi-rs/wasm-runtime": { "version": "1.2.6", "resolved": "https://registry.npmjs.org/@napi-rs/wasm-runtime/-/wasm-runtime-1.2.6.tgz", @@ -3737,9 +3995,9 @@ "license": "MIT" }, "node_modules/@types/estree": { - "version": "1.0.10", - "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.10.tgz", - "integrity": "sha512-lTyOMnOcmRBzdCv6/4zUZCrEhV0xrqQiUZBZtVcbmLHBXKLnN8q89v/wKRF/Q0HbwVsqbIG3o5HDoFl9sduM+g==", + "version": "1.0.11", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.11.tgz", + "integrity": "sha512-YBdNe5JcjYR0sPhJW1QIeRCmI11YhYvaRuGCs9+WCeTTb+Yhb2BE2XMe5/wAqF10FK5g3+q1PDhQABfT7aX0gg==", "dev": true, "license": "MIT" }, @@ -3750,19 +4008,44 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/linkify-it": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@types/linkify-it/-/linkify-it-5.0.0.tgz", + "integrity": "sha512-sVDA58zAw4eWAffKOaQH5/5j3XeayukzDk+ewSsnv3p4yJEZHCCzMDiZM8e0OUrRvmpGZ85jf4yDHkHsgBNr9Q==", + "dev": true, + "license": "MIT" + }, + "node_modules/@types/markdown-it": { + "version": "14.2.0", + "resolved": "https://registry.npmjs.org/@types/markdown-it/-/markdown-it-14.2.0.tgz", + "integrity": "sha512-NoQ2yGlLWj4wpxMs+TYmRKk3thDrQ97agr7sFqfLsAlvoS8SNQuTrlObhFqG9iugdTtgOE9jpJ6FNM4ZGsa5xQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/linkify-it": "^5", + "@types/mdurl": "^2" + } + }, + "node_modules/@types/mdurl": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/@types/mdurl/-/mdurl-2.0.0.tgz", + "integrity": "sha512-RGdgjQUZba5p6QEFAVx2OGb8rQDL/cPRG7GiedRzMcJ1tYnUANBncjbSB1NRGwbvjcPeikRABz2nshyPk1bhWg==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/node": { - "version": "22.20.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.20.5.tgz", - "integrity": "sha512-U2+DNr+wSjpsTS/wZGYHq7GcwfuSmKiKvoPvK22zwTlRhU91yOniN4qRR5KhIjvif7ysw/dz/hKmfDH0Ris4aA==", + "version": "22.20.7", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.20.7.tgz", + "integrity": "sha512-F/Mcc4pD3YwXQCG50hb8BjB5RmrOere6hge7n2XHf0V8tpkZOVEjwYv9Ql7n0MpMn8Bv7+q12P9w6UHsBm0Sfw==", "license": "MIT", "dependencies": { "undici-types": "~6.21.0" } }, "node_modules/@types/react": { - "version": "19.3.0", - "resolved": "https://registry.npmjs.org/@types/react/-/react-19.3.0.tgz", - "integrity": "sha512-N0rFCuH9YoxG9/m61l9MfpJKfmLOVU0em7ipIz6TRgSSkvReLB9vL85GB+yr8Bs5leqpvg96JSwF4ZS1s4viQg==", + "version": "19.3.3", + "resolved": "https://registry.npmjs.org/@types/react/-/react-19.3.3.tgz", + "integrity": "sha512-K8uWpJc4teiuOPdiP1umjeA9rGMgVPiXuoL66fcS1QlwBT1WMqY8PORmub9FadopIs+RCW6siYEs7Lpq+vDlog==", "license": "MIT", "peer": true, "dependencies": { @@ -3805,9 +4088,9 @@ } }, "node_modules/@typescript-eslint/eslint-plugin/node_modules/ignore": { - "version": "7.0.16", - "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.16.tgz", - "integrity": "sha512-52N+Y4HRMOJmbLmr+DqO4iSRyyB7N52gm7PWCT6h0p978+oKbqHCB7gIJIwZvBUsjlSdWbrBFqUSmIFNZMpn0A==", + "version": "7.0.17", + "resolved": "https://registry.npmjs.org/ignore/-/ignore-7.0.17.tgz", + "integrity": "sha512-0c3zcBRlWmcKhcIQWckzkYncJRv5HHB8O32wO/FcWL8DDXWDJgiEF6SX9ThbTv5h/eZ+xJK+VvDjjQ+cQJhp3Q==", "dev": true, "license": "MIT", "engines": { @@ -4012,23 +4295,23 @@ } }, "node_modules/@uiw/codemirror-theme-vscode": { - "version": "4.25.12", - "resolved": "https://registry.npmjs.org/@uiw/codemirror-theme-vscode/-/codemirror-theme-vscode-4.25.12.tgz", - "integrity": "sha512-sIO/8/hJsT6meSa/d5RQHXw4isago+DP4iVQtqiULvaXaA3cQvtHVw0enbcZdwtVIT6rQEfERxqeoHiX9Psd5w==", + "version": "4.25.13", + "resolved": "https://registry.npmjs.org/@uiw/codemirror-theme-vscode/-/codemirror-theme-vscode-4.25.13.tgz", + "integrity": "sha512-EaqMHexflhyio53qT5tmEVMOwGFdqGos4q9LY2M74EeAQBR1nP0LbHJBLxMLQGLtgpOLutce7jeIUyFZuA5g1g==", "license": "MIT", "dependencies": { "@babel/runtime": "^7.18.6", "@lezer/highlight": "^1.0.0", - "@uiw/codemirror-themes": "4.25.12" + "@uiw/codemirror-themes": "4.25.13" }, "funding": { "url": "https://jaywcjlove.github.io/#/sponsor" } }, "node_modules/@uiw/codemirror-themes": { - "version": "4.25.12", - "resolved": "https://registry.npmjs.org/@uiw/codemirror-themes/-/codemirror-themes-4.25.12.tgz", - "integrity": "sha512-3bLX6C+gstr82SmY2FAj2TfHXnl2SnC+whRZJmRsv82wMhG8RZlZVy+o0rLuGRIPD9acuY0gpouHVRNUnzBj3g==", + "version": "4.25.13", + "resolved": "https://registry.npmjs.org/@uiw/codemirror-themes/-/codemirror-themes-4.25.13.tgz", + "integrity": "sha512-2sai+4dRRrbutz4jHyHaJDYf7beTdRYN3p1ciiE/spEH03grc58f8n2yNnUQRz3zjFRALDjMnzEu8A5LukMKyQ==", "license": "MIT", "dependencies": { "@codemirror/language": "^6.0.0", @@ -4584,6 +4867,16 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/axe-core": { + "version": "4.14.1", + "resolved": "https://registry.npmjs.org/axe-core/-/axe-core-4.14.1.tgz", + "integrity": "sha512-FHfa+lmNjQZfJz1q8wKqIDwC6DExcHt/pkjNQb09a3NPjCKg2rhu5qb2S4r76ASyFNNtuFooJpZe37OgudVGtQ==", + "dev": true, + "license": "MPL-2.0", + "engines": { + "node": ">=4" + } + }, "node_modules/babel-plugin-polyfill-corejs2": { "version": "0.4.17", "resolved": "https://registry.npmjs.org/babel-plugin-polyfill-corejs2/-/babel-plugin-polyfill-corejs2-0.4.17.tgz", @@ -4839,9 +5132,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001827", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001827.tgz", - "integrity": "sha512-YWEDr46gSO81M8w6uPbaIy4++IXsirx2asUqvllNiD4BPf75ibxclUjWEqp8ObCenRv+UM2n5Y8xuRPT8V8FrQ==", + "version": "1.0.30001828", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001828.tgz", + "integrity": "sha512-7MWeT+3DlrpuDybTWHl4Zb1Z80Z1fLLnOXuBjDXebzDVcqnEWUlV8JcbASg8B8BhcW8QT2UiR1KAtzYFIZHZYA==", "dev": true, "funding": [ { @@ -5335,9 +5628,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.5.492", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.492.tgz", - "integrity": "sha512-4uMs7omhajKiud0GqALLTazS/zyvHLTLmDWVTR+e6BnyJo5bSNrph/JoRWEFJJmY75ct9hCiSGsbFF9fLe5gDw==", + "version": "1.5.494", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.5.494.tgz", + "integrity": "sha512-Tph7ohL4Xc0ft3DXElYEIVTmPI3H0MtPCTdgtz5AwWGZG6q+vMiT3IzJ3RJX/HJQ8pYzeimQyvi6SsBTOS0nyQ==", "dev": true, "license": "ISC" }, @@ -5361,10 +5654,9 @@ } }, "node_modules/entities": { - "version": "9.0.0", - "resolved": "https://registry.npmjs.org/entities/-/entities-9.0.0.tgz", - "integrity": "sha512-oJFNDJg3kTPwAD1cNn2+WmUq4wFoo09npc3Ydf1D7ED4smRiWrsKnaLxykrTWgyGEcusc87P5dxlAleol9kpkg==", - "dev": true, + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-8.1.0.tgz", + "integrity": "sha512-kxL7msIffSuh9aaFAMD7rxAIuTRMAHMeBtgHW2yUdWw732ZNh4MehkF2gdjvtdmikkaIP9bFDDJOPlsvm7avrA==", "license": "BSD-2-Clause", "engines": { "node": ">=20.19.0" @@ -7951,6 +8243,25 @@ "url": "https://opencollective.com/parcel" } }, + "node_modules/linkify-it": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-6.1.0.tgz", + "integrity": "sha512-wJ/TwpSDTLepCrQoYWYIExIKg5Zchex2Nn5yk2mFnB+6PtdkHtyLx742md9csRjjOnGkKIS/RrbY7l8D6gT9Vw==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/puzrin" + }, + { + "type": "github", + "url": "https://github.com/sponsors/markdown-it" + } + ], + "license": "MIT", + "dependencies": { + "uc.micro": "^3.0.0" + } + }, "node_modules/lit": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/lit/-/lit-3.3.3.tgz", @@ -8016,6 +8327,13 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/lodash-es": { + "version": "4.18.1", + "resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.18.1.tgz", + "integrity": "sha512-J8xewKD/Gk22OZbhpOVSwcs60zhd95ESDwezOFuA3/099925PdHJ7OFHNTGtajL3AlZkykD32HykiMo+BIBI8A==", + "dev": true, + "license": "MIT" + }, "node_modules/lodash.debounce": { "version": "4.0.8", "resolved": "https://registry.npmjs.org/lodash.debounce/-/lodash.debounce-4.0.8.tgz", @@ -8053,9 +8371,9 @@ } }, "node_modules/lucide": { - "version": "1.78.0", - "resolved": "https://registry.npmjs.org/lucide/-/lucide-1.78.0.tgz", - "integrity": "sha512-4lMWPv+OZGL1N2jkTNGjw86Rd3+4gyCdBHHXw+emfCvbQEojOPwPQo20y4SEUxy5ZBc3IDp3KC1vA7PPiuLbQA==", + "version": "1.80.0", + "resolved": "https://registry.npmjs.org/lucide/-/lucide-1.80.0.tgz", + "integrity": "sha512-3tsjW2GIkBNMYHlpnOUA4bP5jAh20iRHksM92tSsCzu24BktkK103HJfOqPybqJtDgYnY5NEf6LEyBiq0N+KjA==", "license": "ISC" }, "node_modules/lz-string": { @@ -8106,16 +8424,59 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/markdown-it": { + "version": "15.0.3", + "resolved": "https://registry.npmjs.org/markdown-it/-/markdown-it-15.0.3.tgz", + "integrity": "sha512-+Az7Ojz3iRGu8KYMvJ6xVhvrxP3eE+vEtJX75Ow88XBpcQNV/0lGX5ZynIIBftREo4DC2jsveAMDaeltmm8QvQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/puzrin" + }, + { + "type": "github", + "url": "https://github.com/sponsors/markdown-it" + } + ], + "license": "MIT", + "dependencies": { + "argparse": "^3.0.3", + "entities": "^8.1.0", + "linkify-it": "^6.1.0", + "mdurl": "^2.1.0", + "punycode.js": "^2.3.1", + "uc.micro": "^3.0.0" + }, + "bin": { + "markdown-it": "bin/markdown-it.mjs" + } + }, + "node_modules/markdown-it/node_modules/argparse": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/argparse/-/argparse-3.0.4.tgz", + "integrity": "sha512-fwWK3Zq22l4XJJjx5mcBHGikIk+hJqO+32dPm0Jur7+rtG5x1scOjSfdT9ZKeWHPpsya/l0HHK4tDImBkTrtvA==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/puzrin" + }, + { + "type": "github", + "url": "https://github.com/sponsors/nodeca" + } + ], + "license": "PSF-2.0" + }, "node_modules/marked": { - "version": "18.2.1", - "resolved": "https://registry.npmjs.org/marked/-/marked-18.2.1.tgz", - "integrity": "sha512-ii4bxCTCqqwpT86XZWgJNs+ZnAIZksmLGYMViWA7PDIXYIeNo1x6cDdX3JOip9NM/cI6p8z57FxliACboTruMA==", + "version": "11.2.0", + "resolved": "https://registry.npmjs.org/marked/-/marked-11.2.0.tgz", + "integrity": "sha512-HR0m3bvu0jAPYiIvLUUQtdg1g6D247//lvcekpHO1WMvbwDlwSkZAX9Lw4F4YHE1T0HaaNve0tuAWuV1UJ6vtw==", "license": "MIT", "bin": { "marked": "bin/marked.js" }, "engines": { - "node": ">= 20" + "node": ">= 18" } }, "node_modules/math-intrinsics": { @@ -8134,6 +8495,12 @@ "dev": true, "license": "CC0-1.0" }, + "node_modules/mdurl": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/mdurl/-/mdurl-2.1.0.tgz", + "integrity": "sha512-1+HBaOx0zi/dQWht8rNv9MYf9qqpqL/kxI0hXImU6Y547zM6Sni8BQibt7ifgMcYtQg41ao3Ivd6cnSM86inpg==", + "license": "MIT" + }, "node_modules/meeting-pane": { "version": "4.1.1-0", "resolved": "https://registry.npmjs.org/meeting-pane/-/meeting-pane-4.1.1-0.tgz", @@ -8781,6 +9148,19 @@ "url": "https://github.com/inikulin/parse5?sponsor=1" } }, + "node_modules/parse5/node_modules/entities": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/entities/-/entities-9.0.0.tgz", + "integrity": "sha512-oJFNDJg3kTPwAD1cNn2+WmUq4wFoo09npc3Ydf1D7ED4smRiWrsKnaLxykrTWgyGEcusc87P5dxlAleol9kpkg==", + "dev": true, + "license": "BSD-2-Clause", + "engines": { + "node": ">=20.19.0" + }, + "funding": { + "url": "https://github.com/fb55/entities?sponsor=1" + } + }, "node_modules/patch-package": { "version": "8.0.1", "resolved": "https://registry.npmjs.org/patch-package/-/patch-package-8.0.1.tgz", @@ -8849,6 +9229,18 @@ "dev": true, "license": "MIT" }, + "node_modules/pdfjs-dist": { + "version": "6.5.438", + "resolved": "https://registry.npmjs.org/pdfjs-dist/-/pdfjs-dist-6.5.438.tgz", + "integrity": "sha512-vg8Pw1x+AFKy4AMDvhuWl5cOYV8d698UoEANoFFhc79hqXDnZQqnOXoxw3HG907WHOg1JYOvLhP756boddFxpA==", + "license": "Apache-2.0", + "engines": { + "node": ">=22.13.0 || >=24" + }, + "optionalDependencies": { + "@napi-rs/canvas": "^1.0.13" + } + }, "node_modules/peowly": { "version": "1.3.3", "resolved": "https://registry.npmjs.org/peowly/-/peowly-1.3.3.tgz", @@ -9080,6 +9472,15 @@ "node": ">=6" } }, + "node_modules/punycode.js": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/punycode.js/-/punycode.js-2.3.1.tgz", + "integrity": "sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/qrcode": { "version": "1.5.4", "resolved": "https://registry.npmjs.org/qrcode/-/qrcode-1.5.4.tgz", @@ -10147,9 +10548,9 @@ "license": "MIT" }, "node_modules/tinyexec": { - "version": "1.3.1", - "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.3.1.tgz", - "integrity": "sha512-GCvB3aoys96IuDFBMcTB46JOR6mdMtAToqwiW8JlWhsoh1mhHi/xn9ss/Dg7N555GiJyEt2qzoG/NHCwM6h1EA==", + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/tinyexec/-/tinyexec-1.4.0.tgz", + "integrity": "sha512-PV6lIcJQh57aFeJDwx16JNHmgFRh5xguzallrDW1qe8nAghYgr5MKz2K5k7wEyV/ygZhdnIAP8+HZSarHPBCsg==", "dev": true, "license": "MIT", "engines": { @@ -10184,22 +10585,22 @@ } }, "node_modules/tldts": { - "version": "7.5.5", - "resolved": "https://registry.npmjs.org/tldts/-/tldts-7.5.5.tgz", - "integrity": "sha512-Hy6IImaWALzJOgCIss4gIFi4G0M9lqk95pFKCUVxQPZw+biZ1Pv6f28JpYgahpJB+BufA0HYsIU/aP/WIx3KRg==", + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/tldts/-/tldts-7.6.0.tgz", + "integrity": "sha512-IFk9SJW/EhTZMpJA1zRdP+69JK4NmJbMx1aRdJvLBR9em1k62eWiwolSWlDRpRdkaAnZ1dDCwFPmRPBNuLGGHA==", "dev": true, "license": "MIT", "dependencies": { - "tldts-core": "^7.5.5" + "tldts-core": "^7.6.0" }, "bin": { "tldts": "bin/cli.js" } }, "node_modules/tldts-core": { - "version": "7.5.5", - "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-7.5.5.tgz", - "integrity": "sha512-rEJz/8cJFY/bdF354gl14yxavbrIbvM+FcbkYVQ6CSCMQTJdUFUIm39TTWSiGPvcpQh7/F6qHrD3SkwwdgtDCw==", + "version": "7.6.0", + "resolved": "https://registry.npmjs.org/tldts-core/-/tldts-core-7.6.0.tgz", + "integrity": "sha512-0By9U6fw2hNzfJAbBMuo1bsX/OyVlsj0wjGyMPV50RZKoLCRwXBOX0FQqgZDaMo2WjjaEW/ZGyVXicLUFTmXqQ==", "dev": true, "license": "MIT" }, @@ -10422,6 +10823,12 @@ "typescript": ">=4.8.4 <6.1.0" } }, + "node_modules/uc.micro": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/uc.micro/-/uc.micro-3.0.0.tgz", + "integrity": "sha512-U3PppEkleoTnIfi8BozMx3yju3qc/L6SwqWo2Sw+54PX+PX0q9I+r1Um5HCmqD7n9VDX5/v3vQH/AjA6deDdtw==", + "license": "MIT" + }, "node_modules/ufo": { "version": "1.6.4", "resolved": "https://registry.npmjs.org/ufo/-/ufo-1.6.4.tgz", @@ -11226,6 +11633,37 @@ } } }, + "node_modules/vitest-axe": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/vitest-axe/-/vitest-axe-0.1.0.tgz", + "integrity": "sha512-jvtXxeQPg8R/2ANTY8QicA5pvvdRP4F0FsVUAHANJ46YCDASie/cuhlSzu0DGcLmZvGBSBNsNuK3HqfaeknyvA==", + "dev": true, + "license": "MIT", + "dependencies": { + "aria-query": "^5.0.0", + "axe-core": "^4.4.2", + "chalk": "^5.0.1", + "dom-accessibility-api": "^0.5.14", + "lodash-es": "^4.17.21", + "redent": "^3.0.0" + }, + "peerDependencies": { + "vitest": ">=0.16.0" + } + }, + "node_modules/vitest-axe/node_modules/chalk": { + "version": "5.6.2", + "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.6.2.tgz", + "integrity": "sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.17.0 || ^14.13 || >=16.0.0" + }, + "funding": { + "url": "https://github.com/chalk/chalk?sponsor=1" + } + }, "node_modules/vscode-jsonrpc": { "version": "10.0.1", "resolved": "https://registry.npmjs.org/vscode-jsonrpc/-/vscode-jsonrpc-10.0.1.tgz", diff --git a/package.json b/package.json index b7bf4c65..9f503fb4 100644 --- a/package.json +++ b/package.json @@ -64,11 +64,13 @@ "dompurify": "^3.4.4", "folder-pane": "4.1.5-0", "issue-pane": "4.1.1-0", + "lit": "^3.3.3", "lit-html": "^3.3.2", - "marked": "^18.0.3", + "markdown-it": "^15.0.3", "meeting-pane": "4.1.1-0", "mime-types": "^3.0.2", "pane-registry": "5.1.2-0", + "pdfjs-dist": "^6.5.438", "profile-pane": "4.1.1-0", "rdflib": "2.4.1", "solid-logic": "6.2.1-0", @@ -83,9 +85,11 @@ "@iconify/json": "2.2.494", "@testing-library/dom": "^10.4.1", "@testing-library/jest-dom": "^6.9.1", + "@types/markdown-it": "^14.2.0", "@types/node": "^22.20.0", "@typescript-eslint/parser": "^8.59.3", "@vitest/coverage-v8": "^4.0.18", + "axe-core": "^4.14.1", "eslint": "^9.39.4", "globals": "^17.6.0", "jsdom": "^28.1.0", @@ -94,7 +98,8 @@ "typescript": "^6.0.3", "unplugin-icons": "^23.0.1", "vite": "^8.0.16", - "vitest": "^4.0.18" + "vitest": "^4.0.18", + "vitest-axe": "^0.1.0" }, "solidosDependencies": [ "rdflib", diff --git a/src/components/iframe-preview/IframePreview.styles.css b/src/components/iframe-preview/IframePreview.styles.css new file mode 100644 index 00000000..b129d73e --- /dev/null +++ b/src/components/iframe-preview/IframePreview.styles.css @@ -0,0 +1,23 @@ +:host { + display: flex; + flex: 1 1 0%; + min-height: 0; + min-width: 0; +} + +.editor-card, +.human-readable-pane__container--iframe { + display: flex; + flex: 1 1 0%; + flex-direction: column; + min-height: 0; + min-width: 0; +} + +.human-readable-pane__frame--iframe { + flex: 1 1 0%; + width: 100%; + min-height: 0; + box-sizing: border-box; + border: 1px solid var(--solid-ui-color-slate-200, #E2E8F0); +} diff --git a/src/components/iframe-preview/IframePreview.ts b/src/components/iframe-preview/IframePreview.ts new file mode 100644 index 00000000..7bf731ad --- /dev/null +++ b/src/components/iframe-preview/IframePreview.ts @@ -0,0 +1,169 @@ +import { html, nothing } from 'lit' +import { property, state } from 'lit/decorators.js' +import { customElement, WebComponent } from 'solid-ui' +import type { LiveStore, NamedNode } from 'rdflib' +import { + documentTitle, + HTML_PREVIEW_SANDBOX, + IFRAME_PREVIEW_FRAME_NAME, + resourceFilename, + addResponsivePreviewStyles +} from '../../humanReadable/previewHelpers' +import styles from './IframePreview.styles.css' +import 'solid-ui/components/error-state' + +@customElement('solid-panes-iframe-preview') +export default class IframePreview extends WebComponent { + static styles = styles + + @property({ attribute: false }) + accessor store: LiveStore | undefined = undefined + + @property({ attribute: false }) + accessor subject: NamedNode | undefined = undefined + + @state() + private accessor contentType: string | null = null + + @state() + private accessor content: string | undefined = undefined + + @state() + private accessor errorMessage = '' + + @state() + private accessor dokieliHtml = false + + @state() + private accessor fetchedTitle = '' + + @property({ attribute: false }) + accessor rememberHtmlType: ((uri: string, isDokieli: boolean) => void) | undefined + + @property({ attribute: false }) + accessor withBaseHref: ((html: string, uri: string) => string) | undefined + + @property({ attribute: false }) + accessor isDokieliHtml: ((html: string) => boolean) | undefined + + @property({ attribute: false }) + accessor mountDokieliBridge: + ((frame: HTMLIFrameElement, uri: string, html: string) => () => void) | undefined + + private objectUrl: string | undefined + private removeDokieliBridge = () => {} + private rawHtml: string | undefined + private fetchGeneration = 0 + + private get previewTitle (): string { + return this.fetchedTitle || (this.subject?.uri ? resourceFilename(this.subject.uri) : 'preview') + } + + private dismissError = (): void => { + this.errorMessage = '' + } + + private clearPreview (): void { + this.removeDokieliBridge() + this.removeDokieliBridge = () => {} + this.renderRoot.querySelector('iframe')?.removeAttribute('srcdoc') + if (this.objectUrl) { + URL.revokeObjectURL(this.objectUrl) + this.objectUrl = undefined + } + this.content = undefined + this.contentType = null + this.rawHtml = undefined + this.fetchedTitle = '' + this.dokieliHtml = false + this.errorMessage = '' + } + + private async fetchDocument (): Promise { + const generation = ++this.fetchGeneration + const { subject, store } = this + this.clearPreview() + if (!subject || !store) return + + const isCurrent = () => this.isConnected && + generation === this.fetchGeneration && this.subject === subject && this.store === store + + try { + const response = await store.fetcher._fetch(subject.uri) + if (!response.ok) throw new Error(`HTTP ${response.status}`) + const contentType = response.headers.get('content-type')?.split(';', 1)[0].trim().toLowerCase() ?? null + const isHtml = contentType === 'text/html' || contentType === 'application/xhtml+xml' + + if (isHtml) { + const htmlContent = await response.text() + if (!isCurrent()) return + this.dokieliHtml = this.isDokieliHtml?.(htmlContent) ?? false + this.rememberHtmlType?.(subject.uri, this.dokieliHtml) + this.rawHtml = htmlContent + this.fetchedTitle = documentTitle(htmlContent, subject.uri) + this.contentType = contentType + const documentHtml = this.withBaseHref?.(htmlContent, subject.uri) ?? htmlContent + this.content = addResponsivePreviewStyles(documentHtml) + } else { + const blob = await response.blob() + if (!isCurrent()) return + this.objectUrl = URL.createObjectURL(blob) + this.contentType = contentType + this.content = this.objectUrl + } + } catch (error) { + if (isCurrent()) { + this.errorMessage = error instanceof Error ? error.message : String(error) + } + } + } + + connectedCallback (): void { + super.connectedCallback() + if (this.hasUpdated) this.fetchDocument() + } + + protected updated (changed: Map): void { + super.updated(changed) + if (changed.has('subject') || changed.has('store')) { + this.fetchDocument() + } else if (changed.has('content') && this.dokieliHtml && this.rawHtml && this.subject) { + const frame = this.renderRoot.querySelector('iframe') + if (frame && this.mountDokieliBridge) { + this.removeDokieliBridge() + this.removeDokieliBridge = this.mountDokieliBridge(frame, this.subject.uri, this.rawHtml) + } + } + } + + disconnectedCallback (): void { + ++this.fetchGeneration + this.clearPreview() + super.disconnectedCallback() + } + + render () { + const isHtml = this.contentType === 'text/html' || this.contentType === 'application/xhtml+xml' + return html` +
+
+ +
+ ${this.errorMessage + ? html`` + : nothing} +
+ ` + } +} diff --git a/src/components/iframe-preview/index.ts b/src/components/iframe-preview/index.ts new file mode 100644 index 00000000..95aaaac1 --- /dev/null +++ b/src/components/iframe-preview/index.ts @@ -0,0 +1,4 @@ +import IframePreview from './IframePreview' + +export { IframePreview } +export default IframePreview diff --git a/src/components/pdf-viewer/PdfViewer.ts b/src/components/pdf-viewer/PdfViewer.ts new file mode 100644 index 00000000..fc57f9ed --- /dev/null +++ b/src/components/pdf-viewer/PdfViewer.ts @@ -0,0 +1,344 @@ +import { html, nothing, TemplateResult } from 'lit' +import { property, state } from 'lit/decorators.js' +import { customElement, WebComponent } from 'solid-ui' +import type { LiveStore, NamedNode } from 'rdflib' +import { resourceFilename } from '../../humanReadable/previewHelpers' +import 'solid-ui/components/error-state' +import styles from './PdfViewier.styles.css' +import pdfWorkerUrl from 'pdfjs-dist/build/pdf.worker.min.mjs?url' + +type PdfJsModule = typeof import('pdfjs-dist') +type PdfDocument = Awaited['promise']> +let pdfJsModulePromise: Promise | undefined + +function loadPdfJs (): Promise { + if (!pdfJsModulePromise) { + pdfJsModulePromise = import('./pdfJs').then(module => module.default) + } + return pdfJsModulePromise +} + +@customElement('solid-panes-pdf-viewer') +export default class PdfViewer extends WebComponent { + static styles = styles + + @property({ attribute: false }) + accessor store: LiveStore | undefined = undefined + + @property({ attribute: false }) + accessor subject: NamedNode | undefined = undefined + + @state() + private accessor errorMessage = '' + + protected pdfJs: PdfJsModule | undefined + protected pdfData: ArrayBuffer | undefined + private pdfDocument: PdfDocument | undefined + private pdfLoadingTask: ReturnType | undefined + private fetchGeneration = 0 + private effectiveMobileLayout = false + private readonly maxConcurrentRenders = 2 + private pageObserver: IntersectionObserver | undefined + private readonly visibleMobilePages = new Set() + private readonly renderedPages = new Set() + private renderQueue: Promise = Promise.resolve() + private readonly handleViewportChange = (): void => { + const mobile = this.isMobileLayout() + if (mobile === this.effectiveMobileLayout || !this.pdfDocument) return + this.effectiveMobileLayout = mobile + const generation = this.fetchGeneration + Promise.all([ + this.renderMainCanvases(generation), + this.renderThumbnailCanvases(generation) + ]).catch(error => { + if (generation === this.fetchGeneration) { + this.errorMessage = error instanceof Error ? error.message : String(error) + } + }) + } + + private async renderPageBatch (pageNumbers: number[], generation: number): Promise { + const render = this.renderQueue.then(async () => { + const pending = pageNumbers.filter(pageNumber => !this.renderedPages.has(pageNumber)) + const canvases = this.renderRoot.querySelectorAll('.canvas') + for (let start = 0; start < pending.length; start += this.maxConcurrentRenders) { + await Promise.all(pending.slice(start, start + this.maxConcurrentRenders).map(async pageNumber => { + const canvas = canvases[pageNumber - 1] + if (!canvas) return + await this.renderPage(pageNumber, canvas, 1.25, generation) + if (generation === this.fetchGeneration) this.renderedPages.add(pageNumber) + })) + } + }) + this.renderQueue = render.catch(() => {}) + await render + } + + private observeMobilePages (generation: number): void { + this.pageObserver?.disconnect() + if (!this.isMobileLayout() || typeof IntersectionObserver === 'undefined') return + const pages = this.renderRoot.querySelectorAll('.page') + this.pageObserver = new IntersectionObserver(entries => { + entries.forEach(entry => { + const pageNumber = Number((entry.target as HTMLElement).dataset.page) + if (entry.isIntersecting) this.visibleMobilePages.add(pageNumber) + else this.visibleMobilePages.delete(pageNumber) + }) + if (this.visibleMobilePages.size === 0) return + const visible = Array.from(this.visibleMobilePages) + const firstVisible = Math.min(...visible) + const lastVisible = Math.max(...visible) + const keep = new Set( + Array.from( + { length: lastVisible - firstVisible + 3 }, + (_, index) => Math.max(1, firstVisible - 1 + index) + ).filter(pageNumber => pageNumber <= this.pageCount) + ) + this.releaseDistantPages(keep) + this.renderPageBatch(Array.from(keep), generation).catch(error => { + if (generation === this.fetchGeneration) { + this.errorMessage = error instanceof Error ? error.message : String(error) + } + }) + }, { root: this.renderRoot.querySelector('.main'), rootMargin: '800px 0px' }) + pages.forEach(page => this.pageObserver?.observe(page)) + } + + private releaseDistantPages (keep: Set): void { + if (!this.isMobileLayout()) return + const canvases = this.renderRoot.querySelectorAll('.canvas') + this.renderedPages.forEach(pageNumber => { + if (keep.has(pageNumber)) return + const canvas = canvases[pageNumber - 1] + if (canvas) { + canvas.width = 0 + canvas.height = 0 + } + this.renderedPages.delete(pageNumber) + }) + } + + @state() + private accessor pageCount = 0 + + @state() + private accessor currentPage = 1 + + private get previewTitle (): string { + return this.subject?.uri ? resourceFilename(this.subject.uri) : 'PDF preview' + } + + private dismissError = (): void => { + this.errorMessage = '' + } + + private isMobileLayout (): boolean { + return this.dataset.layout === 'mobile' || + window.matchMedia?.('(max-width: 768px)').matches === true + } + + private clearDocument (): void { + this.errorMessage = '' + this.pdfJs = undefined + this.pdfData = undefined + if (this.pdfLoadingTask && !this.pdfLoadingTask.destroyed) { + this.pdfLoadingTask.destroy() + } + this.pdfLoadingTask = undefined + if (this.pdfDocument) { + this.pdfDocument.cleanup() + this.pdfDocument = undefined + } + this.pageObserver?.disconnect() + this.pageObserver = undefined + this.renderedPages.clear() + this.visibleMobilePages.clear() + } + + private selectPage (pageNumber: number): void { + if (!this.pdfDocument || pageNumber < 1 || pageNumber > this.pageCount) return + this.currentPage = pageNumber + const generation = this.fetchGeneration + this.renderSelectedPage(pageNumber, generation).catch(error => { + if (generation === this.fetchGeneration) { + this.errorMessage = error instanceof Error ? error.message : String(error) + } + }) + } + + private async renderSelectedPage (pageNumber: number, generation: number): Promise { + await this.updateComplete + await this.renderPageBatch([pageNumber], generation) + } + + private async renderPage ( + pageNumber: number, + canvas: HTMLCanvasElement, + scale: number, + generation: number + ): Promise { + if (!this.pdfDocument || generation !== this.fetchGeneration) return + const page = await this.pdfDocument.getPage(pageNumber) + if (!this.isConnected || generation !== this.fetchGeneration) return + const viewport = page.getViewport({ scale }) + const canvasContext = canvas.getContext('2d') + if (!canvasContext) throw new Error('Unable to create a PDF canvas.') + canvas.width = viewport.width + canvas.height = viewport.height + await page.render({ canvas, canvasContext, viewport }).promise + } + + private async renderMainCanvases (generation: number): Promise { + await this.updateComplete + const canvases = this.renderRoot.querySelectorAll('.canvas') + if (canvases.length === 0) throw new Error('Unable to create a PDF canvas.') + if (this.isMobileLayout()) { + const firstPage = Math.max(1, this.currentPage - 2) + const lastPage = Math.min(this.pageCount, this.currentPage + 2) + await this.renderPageBatch( + Array.from({ length: lastPage - firstPage + 1 }, (_, index) => firstPage + index), + generation + ) + this.observeMobilePages(generation) + return + } + await this.renderPageBatch([this.currentPage], generation) + this.releaseDistantPages(new Set([this.currentPage])) + } + + private async renderThumbnailCanvases (generation: number): Promise { + if (this.isMobileLayout()) return + await this.updateComplete + const canvases = this.renderRoot.querySelectorAll('.thumbnail-canvas') + for (let start = 0; start < canvases.length; start += this.maxConcurrentRenders) { + await Promise.all(Array.from( + { length: Math.min(this.maxConcurrentRenders, canvases.length - start) }, + (_, offset) => this.renderPage(start + offset + 1, canvases[start + offset], 0.18, generation) + )) + } + } + + private async renderMainPage (generation: number): Promise { + if (!this.pdfJs || !this.pdfData) return + + this.pdfJs.GlobalWorkerOptions.workerSrc = pdfWorkerUrl + const loadingTask = this.pdfJs.getDocument({ data: this.pdfData }) + this.pdfLoadingTask = loadingTask + const pdfDocument = await loadingTask.promise + if (!this.isConnected || generation !== this.fetchGeneration) { + await loadingTask.destroy() + return + } + + this.pdfDocument = pdfDocument + this.effectiveMobileLayout = this.isMobileLayout() + this.pageCount = pdfDocument.numPages + this.currentPage = 1 + if (!this.isConnected || generation !== this.fetchGeneration) return + + await this.renderMainCanvases(generation) + await this.renderThumbnailCanvases(generation) + } + + private renderThumbnailLayout (): TemplateResult { + return html` +
+ ${this.pageCount > 0 + ? Array.from({ length: this.pageCount }, (_, index) => html` + + `) + : nothing} +
` + } + + private async fetchDocument (): Promise { + const generation = ++this.fetchGeneration + const { subject, store } = this + this.clearDocument() + if (!subject || !store) return + + const isCurrent = () => this.isConnected && + generation === this.fetchGeneration && this.subject === subject && this.store === store + + try { + const response = await store.fetcher._fetch(subject.uri) + if (!response.ok) throw new Error(`HTTP ${response.status}`) + const pdfData = await response.arrayBuffer() + if (!isCurrent()) return + const pdfJs = await loadPdfJs() + if (!isCurrent()) return + this.pdfJs = pdfJs + this.pdfData = pdfData + await this.renderMainPage(generation) + } catch (error) { + if (isCurrent()) { + this.errorMessage = error instanceof Error ? error.message : String(error) + } + } + } + + connectedCallback (): void { + super.connectedCallback() + this.effectiveMobileLayout = this.isMobileLayout() + window.addEventListener('resize', this.handleViewportChange) + if (this.hasUpdated) this.fetchDocument() + } + + protected updated (changed: Map): void { + super.updated(changed) + if (changed.has('subject') || changed.has('store')) { + this.fetchDocument() + } + } + + disconnectedCallback (): void { + window.removeEventListener('resize', this.handleViewportChange) + ++this.fetchGeneration + this.clearDocument() + super.disconnectedCallback() + } + + render () { + return html` +
+
+
+ + This preview displays pages as images. PDF text and links are not accessible in this preview. + + ${(this.pageCount > 0 ? Array.from({ length: this.pageCount }, (_, index) => index + 1) : [1]).map(pageNumber => html` +
+ +
+ `)} +
+ +
+ ${this.errorMessage + ? html`` + : nothing} +
+ ` + } +} diff --git a/src/components/pdf-viewer/PdfViewier.styles.css b/src/components/pdf-viewer/PdfViewier.styles.css new file mode 100644 index 00000000..5034f4ac --- /dev/null +++ b/src/components/pdf-viewer/PdfViewier.styles.css @@ -0,0 +1,208 @@ +:host { + display: flex; + flex: 1 1 0%; + min-width: 0; + min-height: 0; +} + +.pdf-viewer { + display: flex; + flex: 1 1 0%; + min-width: 0; + min-height: 0; + overflow: hidden; + color: var(--solid-ui-color-gray-800, #2f323f); + background: var(--solid-ui-color-white, #fff); + border: 1px solid var(--solid-ui-color-gray-200, #c7c9d0); +} + +.content { + display: grid; + grid-template-columns: minmax(0, 1fr) 120px; + flex: 1 1 0%; + min-width: 0; + min-height: 0; +} + +.main { + display: flex; + flex: 1 1 0%; + min-width: 0; + min-height: 0; + justify-content: center; + padding: 16px; + overflow: auto; +} + +.main:focus-visible { + outline: 2px solid var(--solid-ui-color-gray-800, #101828); + outline-offset: -2px; +} + +.page { + display: none; + flex: 0 0 auto; + width: 100%; + max-width: 100%; + aspect-ratio: 0.707 / 1; +} + +.page[data-current] { + display: block; +} + +.canvas { + display: block; + width: 100%; + height: auto; + border: 1.316px solid var(--solid-ui-color-gray-400, #99A1AF); +} + +.thumbnails { + position: relative; + min-width: 0; + min-height: 0; +} + +.thumbnail-container { + position: absolute; + inset: 0; + display: flex; + flex-direction: column; + box-sizing: border-box; + padding: 12px 10px; + gap: 25px; + overflow-x: hidden; + overflow-y: auto; +} + +.thumbnail { + display: flex; + flex: 0 0 auto; + flex-direction: column; + align-items: center; + align-self: stretch; + min-width: 44px; + min-height: 44px; +} + +.thumbnail:focus-visible { + outline: 2px solid var(--solid-ui-color-gray-800, #101828); + outline-offset: 2px; +} + +.thumbnail-content { + display: flex; + flex-direction: column; + align-items: center; + align-self: stretch; + gap: 9px; +} + +.thumbnail-canvas { + display: block; + width: 100%; + height: auto; +} + +.thumbnail-label { + display: flex; + flex-direction: column; + justify-content: center; + align-items: center; + width: 20px; + height: 19px; + padding: 10px; + color: var(--solid-ui-color-gray-500, #6a7282); + text-align: center; + font-size: var(--solid-ui-font-size-sm, 0.875rem); + font-weight: 500; +} + +.thumbnail[aria-current='page'] .thumbnail-canvas { + border: 1px solid var(--solid-ui-color-primary, #7c4dff); +} + +.thumbnail[aria-current='page'] .thumbnail-label { + color: var(--solid-ui-color-gray-700, #364153); + background: var(--solid-ui-color-lavender-300, #e6dcff); +} + +@media (max-width: 768px) { + .pdf-viewer { + border-radius: 5px; + } + + .content { + display: flex; + flex-direction: column; + align-items: flex-start; + gap: 20px; + padding: 15px 20px 15px 16px; + box-sizing: border-box; + } + + .main { + width: 100%; + flex-direction: column; + align-items: center; + gap: 20px; + padding: 0; + box-sizing: border-box; + } + + .page { + display: block; + } + + .thumbnails { + display: none; + } + + .thumbnail-container { + display: flex; + align-items: flex-start; + width: 100%; + height: auto; + gap: 8px; + padding: 0; + overflow-x: auto; + overflow-y: hidden; + } + + .thumbnail { + flex: 0 0 58px; + } +} + +:host([data-layout='mobile']) { + .pdf-viewer { + border-radius: 5px; + } + + .content { + display: flex; + flex-direction: column; + align-items: flex-start; + gap: 20px; + padding: 15px 20px 15px 16px; + box-sizing: border-box; + } + + .main { + width: 100%; + flex-direction: column; + align-items: center; + gap: 20px; + padding: 0; + box-sizing: border-box; + } + + .page { + display: block; + } + + .thumbnails { + display: none; + } +} diff --git a/src/components/pdf-viewer/index.ts b/src/components/pdf-viewer/index.ts new file mode 100644 index 00000000..3dd3519f --- /dev/null +++ b/src/components/pdf-viewer/index.ts @@ -0,0 +1,4 @@ +import PdfViewer from './PdfViewer' + +export { PdfViewer } +export default PdfViewer diff --git a/src/components/pdf-viewer/pdfJs.ts b/src/components/pdf-viewer/pdfJs.ts new file mode 100644 index 00000000..b872b0b7 --- /dev/null +++ b/src/components/pdf-viewer/pdfJs.ts @@ -0,0 +1,3 @@ +import * as pdfJs from 'pdfjs-dist' + +export default pdfJs diff --git a/src/dataContentPane.ts b/src/dataContentPane.ts index 8c552449..06107eae 100644 --- a/src/dataContentPane.ts +++ b/src/dataContentPane.ts @@ -198,9 +198,9 @@ export const dataContentPane = { referenceAnchor.setAttribute('class', 'bnodeRef') referenceAnchor.setAttribute( 'aria-label', - `Referenced blank node ${obj.toNT().slice(3)}` + `Referenced blank node ${obj.toNT().slice(2)}` ) - referenceAnchor.textContent = '*' + obj.toNT().slice(3) + referenceAnchor.textContent = '*' + obj.toNT().slice(2) return referenceAnchor } doneBnodes[obj.toNT()] = true @@ -279,8 +279,8 @@ export const dataContentPane = { anchor.setAttribute('id', bNT.slice(2)) anchor.setAttribute('tabindex', '-1') anchor.setAttribute('class', 'bnodeDef') - anchor.setAttribute('aria-label', `Blank node ${bNT.slice(3)}`) - anchor.textContent = bNT.slice(3) + ')' + anchor.setAttribute('aria-label', `Blank node ${bNT.slice(2)}`) + anchor.textContent = bNT.slice(2) + ')' caption.appendChild(anchor) table.insertBefore(caption, table.firstChild) } diff --git a/src/dokieli/dokieliPane.js b/src/dokieli/dokieliPane.ts similarity index 85% rename from src/dokieli/dokieliPane.js rename to src/dokieli/dokieliPane.ts index 4c5d2ca1..b1469dba 100644 --- a/src/dokieli/dokieliPane.js +++ b/src/dokieli/dokieliPane.ts @@ -5,8 +5,8 @@ ** review. It does not use turtle, but RDF/a */ -import * as UI from 'solid-ui' -import * as $rdf from 'rdflib' +import { icons, log, ns } from 'solid-ui' +import { sym } from 'rdflib' import * as mime from 'mime-types' // const DOKIELI_TEMPLATE_URI = 'https://dokie.li/new' // Copy to make new dok @@ -14,11 +14,11 @@ import * as mime from 'mime-types' import DOKIELI_TEMPLATE from './new.js' // Distributed with this library export default { - icon: UI.icons.iconBase + 'dokieli-logo.png', // @@ improve? more like doccument? + icon: icons.iconBase + 'dokieli-logo.png', // @@ improve? more like doccument? name: 'Dokieli', - mintClass: UI.ns.solid('DokieliDocument'), // @@ A better class? + mintClass: ns.solid('DokieliDocument'), // @@ A better class? // Don't provide viewing - let humanReadablePane handle that with appropriate icon label: function (subject, context) { @@ -40,7 +40,7 @@ export default { const contentType = mime.lookup(newInstance.uri) if (!contentType || !contentType.includes('html')) { - newInstance = $rdf.sym(newInstance.uri + '.html') + newInstance = sym(newInstance.uri + '.html') } newPaneOptions.newInstance = newInstance // Save for creation system @@ -65,13 +65,11 @@ export default { contentType: 'text/html' }) .then(function () { - console.log( + log.info( 'new Dokieli document created at ' + newPaneOptions.newInstance ) return newPaneOptions }) } - // render: removed - now handled by humanReadablePane with appropriate dokieli icon } -// ends diff --git a/src/humanReadable/humanReadablePane.css b/src/humanReadable/humanReadablePane.css new file mode 100644 index 00000000..79159115 --- /dev/null +++ b/src/humanReadable/humanReadablePane.css @@ -0,0 +1,368 @@ +.human-readable-pane { + display: flex; + flex-direction: column; + flex: 1 1 auto; + height: 100%; + padding: 0 40px; + margin: 0; + min-height: 0; + min-width: 0; + width: 100%; + max-width: 100%; + box-sizing: border-box; + overflow: auto; +} + +.human-readable-document-container { + display: flex; + flex: 1 1 auto; + flex-direction: column; + min-height: 0; + min-width: 0; + width: 100%; + max-width: 100%; + margin: 0; + padding: 0; + box-sizing: border-box; + overflow-x: hidden; +} + +.human-readable-pane__frame, +.human-readable-document-frame { + display: block; + border: 1px solid var(--solid-ui-color-slate-200, #E2E8F0); + padding: 1rem; + height: var(--human-readable-pane-height, 480px); + min-width: 0; + max-width: 100%; + width: 100%; + box-sizing: border-box; + resize: both; + overflow: auto; +} + +.human-readable-markdown-preview, +.human-readable-plain-text-preview, +.human-readable-json-preview { + flex: 1 1 auto; + height: auto; + min-height: 100%; + max-height: 100%; + resize: none; +} + +.human-readable-pane__frame--iframe { + display: block; + padding: 0; + overflow: hidden; + width: 100%; + max-width: 100%; + min-height: 0; + box-sizing: border-box; + background: var(--color-background, white); +} + +/* Webpages, PDFs and video fill the pane; the framed document scrolls internally. */ +/* Iframe panes fill the explorer and scroll inside the bordered frame, not the pane. */ +.human-readable-pane--iframe, +solid-ui-file-explorer-provider > .paneDiv.human-readable-pane--iframe { + display: flex; + flex: 1 1 0%; + height: 100%; + min-height: 0; + overflow: hidden; +} + +.human-readable-pane__container--iframe { + flex: 1 1 auto; + display: flex; + flex-direction: column; + min-height: 0; +} + +.human-readable-document-status { + display: none; + box-sizing: border-box; + flex: 1 1 auto; + width: 100%; + min-width: 0; + min-height: 0; + align-items: center; + justify-content: center; + padding: 16px; + border: 0; + background: transparent; +} + +.human-readable-document-status[data-visible='true'] { + display: flex; + flex: 1 1 0%; +} + +.human-readable-document-status > solid-ui-error-state { + display: block; + width: 100%; +} + +.human-readable-document-status[data-visible='true'][data-keep-frame='false'] ~ .human-readable-document-frame { + display: none; +} + +.human-readable-pane__container--iframe > .human-readable-pane__frame--iframe { + flex: 1 1 0%; + height: 100%; + min-height: 0; + resize: none; +} + +.human-readable-markdown-preview, +.human-readable-plain-text-preview, +.human-readable-json-preview { + overflow: visible; + max-height: none; +} + +.human-readable-pane--document { + display: flex; + flex: 1 1 0%; + min-height: 0; + overflow: hidden; +} + +.human-readable-pane--document > .human-readable-document-container { + overflow: hidden; +} + +.human-readable-pane--document > .human-readable-document-container > .human-readable-markdown-preview, +.human-readable-pane--document > .human-readable-document-container > .human-readable-plain-text-preview, +.human-readable-pane--document > .human-readable-document-container > .human-readable-json-preview { + flex: 1 1 0%; + height: 100%; + min-height: 0; + max-height: none; + overflow: auto; +} + +.human-readable-markdown-preview { + overflow-wrap: anywhere; + word-break: break-word; +} + +.human-readable-markdown-preview h1, +.human-readable-markdown-preview h2, +.human-readable-markdown-preview h3, +.human-readable-markdown-preview h4, +.human-readable-markdown-preview h5, +.human-readable-markdown-preview h6 { + line-height: 1.25; + margin: 0 0 0.75rem; +} + +.human-readable-markdown-preview a { + color: var(--solid-ui-color-primary, #2563EB); + text-decoration: underline; + text-underline-offset: 0.15em; +} + +.human-readable-markdown-preview blockquote { + border-left: 4px solid var(--solid-ui-color-slate-400, #98A2B3); + margin: 1rem 0; + padding: 0 1rem; +} + +.human-readable-markdown-preview code { + background: var(--solid-ui-color-slate-100, #F1F5F9); + border-radius: 0.25rem; + padding: 0.1em 0.25em; +} + +.human-readable-markdown-preview pre { + background: var(--solid-ui-color-slate-100, #F1F5F9); + border-radius: 0.375rem; + overflow: auto; + padding: 1rem; +} + +.human-readable-markdown-preview pre code { + background: transparent; + padding: 0; +} + +.human-readable-plain-text-preview { + margin: 0; + white-space: pre-wrap; + overflow-wrap: anywhere; + word-break: break-word; +} + +.human-readable-json-preview { + margin: 0; + background: var(--solid-ui-color-slate-50, #F8FAFC); + color: var(--solid-ui-color-gray-900, #101828); + font-family: var(--font-mono, ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace); + font-size: 0.875rem; + line-height: 1.5; + white-space: pre; + overflow: auto; + overflow-wrap: normal; + word-break: normal; + tab-size: 2; +} + +.human-readable-json-preview:focus-visible { + outline: 2px solid var(--solid-ui-color-gray-800, #101828); + outline-offset: -2px; +} + +.human-readable-json-string { + color: #067647; +} + +.human-readable-json-key { + color: #6941c6; + font-weight: 600; +} + +.human-readable-json-number { + color: #175cd3; +} + +.human-readable-json-boolean { + color: #b54708; + font-weight: 600; +} + +.human-readable-json-null { + color: #475467; +} + +.human-readable-json-punctuation { + color: #475467; +} + +.human-readable-plain-text-preview:focus-visible { + outline: 2px solid var(--solid-ui-color-gray-800, #101828); + outline-offset: -2px; +} + +.human-readable-markdown-preview > * { + max-width: 100%; + box-sizing: border-box; +} + +.human-readable-markdown-preview img, +.human-readable-markdown-preview video, +.human-readable-markdown-preview canvas, +.human-readable-markdown-preview iframe { + max-width: 100%; + height: auto; +} + +.human-readable-markdown-preview pre, +.human-readable-markdown-preview code { + max-width: 100%; + overflow-wrap: anywhere; + word-break: break-word; +} + +.human-readable-markdown-preview pre { + white-space: pre-wrap; +} + +.human-readable-markdown-preview table { + border-collapse: collapse; + display: block; + width: 100%; + max-width: 100%; + overflow-x: auto; + box-sizing: border-box; +} + +.human-readable-markdown-preview th, +.human-readable-markdown-preview td { + border: 1px solid var(--solid-ui-color-slate-300, #CBD5E1); + padding: 0.5rem; + white-space: normal; + overflow-wrap: anywhere; + word-break: break-word; +} + +.human-readable-pane[data-layout='mobile'] .human-readable-pane__frame, +.human-readable-pane[data-layout='mobile'] .human-readable-document-frame { + padding: 0.75rem; + resize: none; + min-width: 0; +} + +.human-readable-pane[data-layout='mobile'] .human-readable-markdown-preview, +.human-readable-pane[data-layout='mobile'] .human-readable-plain-text-preview, +.human-readable-pane[data-layout='mobile'] .human-readable-json-preview { + min-height: 100%; + max-height: none; +} + +.human-readable-pane[data-layout='mobile'] { + padding: 0; +} + +.human-readable-pane[data-layout='mobile'] .human-readable-markdown-preview, +.human-readable-pane[data-layout='mobile'] .human-readable-plain-text-preview, +.human-readable-pane[data-layout='mobile'] .human-readable-json-preview { + overflow-wrap: anywhere; + word-break: break-word; +} + +.human-readable-pane[data-layout='mobile'] .human-readable-json-preview { + white-space: pre-wrap; +} + +.human-readable-pane[data-layout='mobile'] .human-readable-pane__frame--iframe { + width: 100%; + max-width: 100%; + flex: 0 0 auto; + min-height: 100vh; + height: 100vh; +} + +@media (max-width: 576px) { + .human-readable-pane { + padding: 0; + } + + .human-readable-pane__frame, + .human-readable-document-frame { + padding: 0.75rem; + resize: none; + min-width: 0; + } + + .human-readable-markdown-preview, + .human-readable-plain-text-preview, + .human-readable-json-preview { + overflow-wrap: anywhere; + word-break: break-word; + } + + .human-readable-json-preview { + white-space: pre-wrap; + } + + .human-readable-pane__frame--iframe { + width: 100%; + max-width: 100%; + flex: 0 0 auto; + min-height: 100vh; + height: 100vh; + } +} + +@media (max-width: 768px) { + .human-readable-pane--iframe, + solid-ui-file-explorer-provider > .paneDiv.human-readable-pane--iframe { + flex: 0 0 auto; + height: 100vh; + height: 100dvh; + min-height: 100vh; + min-height: 100dvh; + } +} diff --git a/src/humanReadable/index.ts b/src/humanReadable/index.ts new file mode 100644 index 00000000..aee8f739 --- /dev/null +++ b/src/humanReadable/index.ts @@ -0,0 +1,541 @@ +/* Human-readable Pane + ** + ** This outline pane contains the document contents for an HTML document + ** This is for peeking at a page, because the user might not want to leave the data browser. + */ +import { icons, log, ns } from 'solid-ui' +import { Util } from 'rdflib' +import { authn } from 'solid-logic' +import type { DataBrowserContext, RenderEnvironment } from 'pane-registry' +import type { NamedNode } from 'rdflib' +import './humanReadablePane.css' +import { createPreviewBridge } from './previewBridge' +import { renderMarkdownContent } from './markdownPreview' +import { renderJsonContent } from './jsonPreview' +import { renderPlainTextContent } from './textPreview' +import { createPreviewContainer } from './previewFrame' +import { escapeAttribute, HTML_PREVIEW_SANDBOX } from './previewHelpers' +import type IframePreview from '../components/iframe-preview' +import '../components/iframe-preview' +import type PdfViewer from '../components/pdf-viewer' +import '../components/pdf-viewer' + +export { IFRAME_PREVIEW_FRAME_NAME } from './previewHelpers' +export { addResponsivePreviewStyles } from './previewHelpers' + +function viewerWebId (): string | null { + try { + return authn.currentUser()?.value ?? null + } catch { + return null + } +} + +// Helper function to check if a URI has a markdown file extension +type DokieliCacheValue = 'dokieli' | 'html' + +type HumanReadableIcon = string | Promise + +type HumanReadablePaneDefinition = { + icon: (subject: NamedNode, context: DataBrowserContext) => HumanReadableIcon + name: string + label: (subject: NamedNode, context: DataBrowserContext) => 'Webpage' | 'View' | null + render: (subject: NamedNode, context: DataBrowserContext) => HTMLDivElement +} + +const isMarkdownFile = (uri?: string | null): boolean => { + if (!uri) return false + const path = uri.split('?')[0].split('#')[0] // Remove query string and fragment + return /\.(md|markdown|mdown|mkd|mkdn)$/i.test(path) +} + +const isJsonFile = (uri?: string | null): boolean => { + if (!uri) return false + const path = uri.split('?')[0].split('#')[0] + return /\.(json|jsonld)$/i.test(path) +} + +const isJsonContentType = (contentType?: string | null): boolean => + contentType === 'application/json' || contentType === 'application/ld+json' + +const canUseJsonExtensionFallback = (contentType?: string | null): boolean => + !contentType || contentType === 'application/octet-stream' + +// Cache for dokieli detection results (keyed by subject URI) +const dokieliCache = new Map() + +const isDokieliHtml = (text: string): boolean => + text.includes('` + const cleanHtml = options.stripPreviewBridgeScripts(html) ?? html + const previewHtml = options.withBaseHref(cleanHtml, uri) + return addResponsivePreviewStyles(previewHtml).replace(/]*)?>/i, match => `${match}${bridge}`) +} diff --git a/src/humanReadable/previewError.ts b/src/humanReadable/previewError.ts new file mode 100644 index 00000000..37ef6f40 --- /dev/null +++ b/src/humanReadable/previewError.ts @@ -0,0 +1,24 @@ +import { html, nothing, render } from 'lit' +import 'solid-ui/components/error-state' + +export function renderPreviewError ( + status: HTMLElement, + title: string, + message: string, + hideFrame = true +): void { + status.dataset.visible = 'true' + status.dataset.keepFrame = String(!hideFrame) + const clearError = () => { + status.dataset.visible = 'false' + delete status.dataset.keepFrame + render(nothing, status) + } + render(html` + + `, status) +} diff --git a/src/humanReadable/previewFrame.ts b/src/humanReadable/previewFrame.ts new file mode 100644 index 00000000..eba5db4d --- /dev/null +++ b/src/humanReadable/previewFrame.ts @@ -0,0 +1,20 @@ +export function createPreviewContainer ( + document: Document, + frame: HTMLElement +): { container: HTMLDivElement, status: HTMLDivElement } { + const container = document.createElement('div') + container.classList.add('human-readable-document-container') + const status = document.createElement('div') + status.className = 'human-readable-document-status' + container.append(status, frame) + return { container, status } +} + +export function configurePreviewFrame ( + frame: HTMLElement, + modifier: 'markdown' | 'plain-text' | 'json' +): void { + frame.className = '' + frame.classList.add('human-readable-document-frame') + frame.classList.add(`human-readable-${modifier}-preview`) +} diff --git a/src/humanReadable/previewHelpers.ts b/src/humanReadable/previewHelpers.ts new file mode 100644 index 00000000..39a0b679 --- /dev/null +++ b/src/humanReadable/previewHelpers.ts @@ -0,0 +1,77 @@ +export const IFRAME_PREVIEW_FRAME_NAME = 'solidos-iframe-preview' +export const HTML_PREVIEW_SANDBOX = 'allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-modals' + +const MOBILE_PREVIEW_STYLES = ` +` + +export function escapeAttribute (value: string): string { + return value.replace(/&/g, '&').replace(/"/g, '"').replace(//g, '>') +} + +export function addResponsivePreviewStyles (html: string): string { + if (html.includes('data-solidos-mobile-preview')) return html + const headMatch = html.match(/]*)?>[\s\S]*?<\/head\s*>/i) + if (headMatch && headMatch.index !== undefined) { + const closingHeadIndex = headMatch.index + headMatch[0].length - headMatch[0].match(/<\/head\s*>$/i)![0].length + return html.slice(0, closingHeadIndex) + MOBILE_PREVIEW_STYLES + html.slice(closingHeadIndex) + } + return MOBILE_PREVIEW_STYLES + html +} + +export function resourceFilename (uri: string): string { + const encodedFilename = uri.split('/').pop() || uri + try { + return decodeURIComponent(encodedFilename) + } catch { + return encodedFilename + } +} + +export function documentTitle (html: string, uri: string): string { + const fallback = resourceFilename(uri) + try { + const title = new DOMParser().parseFromString(html, 'text/html').querySelector('title')?.textContent?.trim() + return title || fallback + } catch { + return fallback + } +} diff --git a/src/humanReadable/textPreview.ts b/src/humanReadable/textPreview.ts new file mode 100644 index 00000000..6675bb6a --- /dev/null +++ b/src/humanReadable/textPreview.ts @@ -0,0 +1,25 @@ +import { log } from 'solid-ui' +import type { DataBrowserContext } from 'pane-registry' +import type { NamedNode } from 'rdflib' +import { html, render } from 'lit-html' +import { configurePreviewFrame } from './previewFrame' +import { renderPreviewError } from './previewError' + +type Store = DataBrowserContext['session']['store'] + +export function renderPlainTextContent ( + store: Store, + subject: NamedNode, + frame: HTMLPreElement, + status: HTMLElement +): void { + configurePreviewFrame(frame, 'plain-text') + store.fetcher.webOperation('GET', subject.uri).then(response => { + const plainText = response.responseText ?? '' + render(html`${plainText}`, frame) + }).catch(error => { + log.debug(`Error fetching plain text content: ${String(error)}`) + renderPreviewError(status, 'Unable to load plain text', 'The document could not be loaded.') + render(html``, frame) + }) +} diff --git a/src/humanReadablePane.css b/src/humanReadablePane.css deleted file mode 100644 index c4c82adc..00000000 --- a/src/humanReadablePane.css +++ /dev/null @@ -1,200 +0,0 @@ -.human-readable-pane { - display: flex; - flex-direction: column; - flex: 1 1 auto; - height: 100%; - padding: 0 40px; - margin: 0; - min-height: 0; - min-width: 0; - width: 100%; - max-width: 100%; - box-sizing: border-box; - overflow: auto; -} - -.human-readable-pane__container { - display: flex; - flex: 1 1 auto; - flex-direction: column; - min-height: 0; - min-width: 0; - width: 100%; - max-width: 100%; - margin: 0; - padding: 0; - box-sizing: border-box; - overflow-x: hidden; -} - -.human-readable-pane__frame { - display: block; - border: 1px solid var(--solid-ui-color-slate-200, #E2E8F0); - padding: 1rem; - height: var(--human-readable-pane-height, 480px); - min-width: 0; - max-width: 100%; - width: 100%; - box-sizing: border-box; - resize: both; - overflow: auto; -} - -.human-readable-pane__frame--markdown, -.human-readable-pane__frame--plain-text { - flex: 1 1 auto; - height: auto; - min-height: 100%; - max-height: 100%; - resize: none; -} - -.human-readable-pane__frame--iframe { - display: block; - padding: 0; - overflow: hidden; - width: 100%; - max-width: 100%; - min-height: 0; - box-sizing: border-box; - background: var(--color-background, white); -} - -/* Webpages, PDFs and video fill the pane; the framed document scrolls internally. */ -/* Iframe panes fill the explorer and scroll inside the bordered frame, not the pane. */ -.human-readable-pane--iframe, -solid-ui-file-explorer-provider > .paneDiv.human-readable-pane--iframe { - display: flex; - flex: 1 1 0%; - height: 100%; - min-height: 0; - overflow: visible; -} - -.human-readable-pane__container--iframe { - flex: 1 1 auto; - display: flex; - flex-direction: column; - min-height: 0; -} - -.human-readable-pane__container--iframe > .human-readable-pane__frame--iframe { - flex: 1 1 auto; - height: 480px; - min-height: 288px; - resize: none; -} - -.human-readable-pane__frame--markdown, -.human-readable-pane__frame--plain-text { - overflow: visible; - max-height: none; -} - -.human-readable-pane__frame--markdown { - overflow-wrap: anywhere; - word-break: break-word; -} - -.human-readable-pane__frame--plain-text { - font-family: monospace; - margin: 0; - white-space: pre-wrap; - overflow-wrap: anywhere; - word-break: break-word; -} - -.human-readable-pane__frame--markdown > * { - max-width: 100%; - box-sizing: border-box; -} - -.human-readable-pane__frame--markdown img, -.human-readable-pane__frame--markdown video, -.human-readable-pane__frame--markdown canvas, -.human-readable-pane__frame--markdown iframe { - max-width: 100%; - height: auto; -} - -.human-readable-pane__frame--markdown pre, -.human-readable-pane__frame--markdown code { - max-width: 100%; - overflow-wrap: anywhere; - word-break: break-word; -} - -.human-readable-pane__frame--markdown pre { - white-space: pre-wrap; -} - -.human-readable-pane__frame--markdown table { - display: block; - width: 100%; - max-width: 100%; - overflow-x: auto; - box-sizing: border-box; -} - -.human-readable-pane__frame--markdown th, -.human-readable-pane__frame--markdown td { - white-space: normal; - overflow-wrap: anywhere; - word-break: break-word; -} - -.human-readable-pane[data-layout='mobile'] .human-readable-pane__frame { - padding: 0.75rem; - resize: none; - min-width: 0; -} - -.human-readable-pane[data-layout='mobile'] .human-readable-pane__frame--markdown, -.human-readable-pane[data-layout='mobile'] .human-readable-pane__frame--plain-text { - min-height: 100%; - max-height: none; -} - -.human-readable-pane[data-layout='mobile'] { - padding: 0; -} - -.human-readable-pane[data-layout='mobile'] .human-readable-pane__frame--markdown, -.human-readable-pane[data-layout='mobile'] .human-readable-pane__frame--plain-text { - overflow-wrap: anywhere; - word-break: break-word; -} - -.human-readable-pane[data-layout='mobile'] .human-readable-pane__frame--iframe { - width: 100%; - max-width: 100%; - flex: 0 0 auto; - min-height: 100vh; - height: 100vh; -} - -@media (max-width: 576px) { - .human-readable-pane { - padding: 0; - } - - .human-readable-pane__frame { - padding: 0.75rem; - resize: none; - min-width: 0; - } - - .human-readable-pane__frame--markdown, - .human-readable-pane__frame--plain-text { - overflow-wrap: anywhere; - word-break: break-word; - } - - .human-readable-pane__frame--iframe { - width: 100%; - max-width: 100%; - flex: 0 0 auto; - min-height: 100vh; - height: 100vh; - } -} diff --git a/src/humanReadablePane.ts b/src/humanReadablePane.ts deleted file mode 100644 index 0c2eba4a..00000000 --- a/src/humanReadablePane.ts +++ /dev/null @@ -1,1072 +0,0 @@ -/* Human-readable Pane - ** - ** This outline pane contains the document contents for an HTML document - ** This is for peeking at a page, because the user might not want to leave the data browser. - */ -import { icons, ns } from 'solid-ui' -import { Util } from 'rdflib' -import { authn } from 'solid-logic' -import { marked } from 'marked' -import DOMPurify from 'dompurify' -import type { DataBrowserContext, RenderEnvironment } from 'pane-registry' -import type { NamedNode } from 'rdflib' -import './humanReadablePane.css' - -function viewerWebId (): string | null { - try { - return authn.currentUser()?.value ?? null - } catch { - return null - } -} - -// Helper function to check if a URI has a markdown file extension -type DokieliCacheValue = 'dokieli' | 'html' - -type HumanReadableIcon = string | Promise - -type HumanReadablePaneDefinition = { - icon: (subject: NamedNode, context: DataBrowserContext) => HumanReadableIcon - name: string - label: (subject: NamedNode, context: DataBrowserContext) => 'Webpage' | 'View' | null - render: (subject: NamedNode, context: DataBrowserContext) => HTMLDivElement -} - -const isMarkdownFile = (uri?: string | null): boolean => { - if (!uri) return false - const path = uri.split('?')[0].split('#')[0] // Remove query string and fragment - return /\.(md|markdown|mdown|mkd|mkdn)$/i.test(path) -} - -const isJsonFile = (uri?: string | null): boolean => { - if (!uri) return false - const path = uri.split('?')[0].split('#')[0] - return /\.json$/i.test(path) -} - -// Cache for dokieli detection results (keyed by subject URI) -const dokieliCache = new Map() - -function applyFrameClasses ( - frame: HTMLElement, - modifier: 'markdown' | 'plain-text' | 'iframe', - lines?: number -): void { - frame.className = '' - frame.classList.add('human-readable-pane__frame') - frame.classList.add(`human-readable-pane__frame--${modifier}`) - if (lines !== undefined) { - frame.style.setProperty('--human-readable-pane-height', `${lines * 16}px`) - } -} - -// window.name of preview iframes; initMainPage refuses to boot SolidOS inside such a frame. -export const HUMAN_READABLE_PREVIEW_FRAME_NAME = 'solidos-human-readable-preview' - -// Scripts may run but get an opaque origin, so previewed pages cannot reach the SolidOS session. -const HTML_PREVIEW_SANDBOX = 'allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-modals' - -const isDokieliHtml = (text: string): boolean => - text.includes('` - const withScript = html.replace(/<\/body\s*>/i, `${script}$&`) - return withScript === html ? `${html}${script}` : withScript -} - -function resourceFilename (uri: string): string { - const encodedFilename = uri.split('/').pop() || uri - try { - return decodeURIComponent(encodedFilename) - } catch { - return encodedFilename - } -} - -function documentTitle (html: string, uri: string): string { - const fallback = resourceFilename(uri) - try { - const title = new DOMParser().parseFromString(html, 'text/html').querySelector('title')?.textContent?.trim() - return title || fallback - } catch { - return fallback - } -} - -type PreviewRequest = { - type: 'solidos-preview-request' - nonce: string - id: string - url: string - method: string - headers?: Record - body?: string -} - -type PreviewResponse = { - type: 'solidos-preview-response' - nonce: string - id: string - ok: boolean - status: number - headers: Array<[string, string]> - body: string - error?: string -} - -const PREVIEW_REQUEST_TYPE = 'solidos-preview-request' -const PREVIEW_RESPONSE_TYPE = 'solidos-preview-response' -const PREVIEW_BRIDGE_ATTRIBUTE = 'data-solidos-preview-bridge' -const PREVIEW_READ_METHODS = new Set(['GET', 'HEAD']) -const PREVIEW_WRITE_METHODS = new Set(['PUT', 'PATCH', 'DELETE']) - -function stripPreviewBridgeScripts (html: string | undefined): string | undefined { - if (typeof html !== 'string' || !html.includes(PREVIEW_REQUEST_TYPE)) return html - - const parsed = new DOMParser().parseFromString(html, 'text/html') - let removed = false - for (const script of parsed.querySelectorAll('script')) { - const source = script.textContent || '' - const isPreviewBridge = script.hasAttribute(PREVIEW_BRIDGE_ATTRIBUTE) || - ( - source.includes(PREVIEW_REQUEST_TYPE) && - source.includes(PREVIEW_RESPONSE_TYPE) && - source.includes('const pending = new Map()') - ) - if (isPreviewBridge) { - script.remove() - removed = true - } - } - if (!removed) return html - - const doctype = html.match(/]*>/i)?.[0] - return `${doctype ? `${doctype}\n` : ''}${parsed.documentElement.outerHTML}` -} - -function isSrcdocUrl (url: string): boolean { - return url === 'about:srcdoc' || /^file:\/\/srcdoc\/?(?:[?#].*)?$/i.test(url) -} - -export function previewRequestUrl (url: string, documentUri: string): string { - const resolvedUrl = new URL(url, documentUri).href - return isSrcdocUrl(resolvedUrl) ? documentUri : resolvedUrl -} - -function profileDocumentUrl (webId: string | null | undefined): string | undefined { - if (!webId) return undefined - try { - const url = new URL(webId) - url.hash = '' - return url.href - } catch { - return undefined - } -} - -export function isAllowedPreviewRequest ( - url: string, - method: string, - documentUri: string, - webId: string | null = null -): boolean { - let resolvedUrl: URL - let expectedUrl: URL - try { - resolvedUrl = new URL(previewRequestUrl(url, documentUri)) - expectedUrl = new URL(documentUri) - } catch { - return false - } - - if (resolvedUrl.origin !== expectedUrl.origin) { - return false - } - - const normalizedMethod = method.toUpperCase() - const requestedDocument = new URL(resolvedUrl.href) - requestedDocument.hash = '' - const expectedDocument = new URL(expectedUrl.href) - expectedDocument.hash = '' - const isPreviewDocument = requestedDocument.href === expectedDocument.href - const isExactPreviewDocument = resolvedUrl.href === expectedUrl.href - // Path-based pods keep the viewer profile below the pod path, e.g. /alice/profile/card. - const isApprovedProfileResource = resolvedUrl.pathname === '/profile/card' || - requestedDocument.href === profileDocumentUrl(webId) - return ( - PREVIEW_READ_METHODS.has(normalizedMethod) && - (isPreviewDocument || isApprovedProfileResource) - ) || (isExactPreviewDocument && PREVIEW_WRITE_METHODS.has(normalizedMethod)) -} - -function createPreviewBridge (html: string, uri: string, nonce: string, webId: string | null = null): string { - const bridge = `` - const cleanHtml = stripPreviewBridgeScripts(html) ?? html - return withBaseHref(cleanHtml, uri).replace(/]*)?>/i, match => `${match}${bridge}`) -} - -function mountDokieliBridge ( - frame: HTMLIFrameElement, - uri: string, - html: string, - authenticatedFetch: (url: string, init?: RequestInit) => Promise, - webId: string | null = null -): void { - const ownerWindow = frame.ownerDocument.defaultView - if (!ownerWindow) return - - const randomValues = new Uint32Array(4) - ownerWindow.crypto.getRandomValues(randomValues) - const nonce = Array.from(randomValues, value => value.toString(16)).join('-') - const expectedUri = new URL(uri).href - const listener = (event: MessageEvent) => { - const request = event.data - if ( - event.source !== frame.contentWindow || - !request || - request.type !== PREVIEW_REQUEST_TYPE || - request.nonce !== nonce - ) return - - const respond = (response: PreviewResponse) => { - frame.contentWindow?.postMessage(response, '*') - } - - // Always settle authenticated bridge requests. Dropping a denied request - // leaves the preview awaiting it forever (Dokieli then never leaves Loading…). - if (!isAllowedPreviewRequest(request.url, request.method, expectedUri, webId)) { - respond({ - type: PREVIEW_RESPONSE_TYPE, - nonce, - id: request.id, - ok: false, - status: 403, - headers: [], - body: '', - error: 'Request not permitted by the SolidOS preview' - }) - return - } - const requestUrl = previewRequestUrl(request.url, expectedUri) - - authenticatedFetch(requestUrl, { - method: request.method, - headers: request.headers, - body: PREVIEW_READ_METHODS.has(request.method) - ? undefined - : stripPreviewBridgeScripts(request.body) - }).then(async response => { - respond({ - type: PREVIEW_RESPONSE_TYPE, - nonce, - id: request.id, - ok: response.ok, - status: response.status, - headers: Array.from(response.headers.entries()), - body: await response.text() - }) - }).catch(error => { - respond({ - type: PREVIEW_RESPONSE_TYPE, - nonce, - id: request.id, - ok: false, - status: 0, - headers: [], - body: '', - error: error instanceof Error ? error.message : String(error) - }) - }) - } - - ownerWindow.addEventListener('message', listener) - frame.setAttribute('sandbox', HTML_PREVIEW_SANDBOX) - frame.srcdoc = createPreviewBridge(html, expectedUri, nonce, webId) -} - -function installPreviewAutoSize ( - frame: HTMLIFrameElement, - ownerWindow: Window -): () => void { - const onMessage = (event: MessageEvent<{ type?: string, height?: number }>) => { - const message = event.data - if ( - event.source !== frame.contentWindow || - message?.type !== 'solidos-preview-size' || - typeof message.height !== 'number' || - !Number.isFinite(message.height) - ) return - frame.style.height = `${Math.max(1, Math.ceil(message.height))}px` - frame.style.flexShrink = '0' - } - ownerWindow.addEventListener('message', onMessage) - return () => ownerWindow.removeEventListener('message', onMessage) -} - -const humanReadablePane: HumanReadablePaneDefinition = { - icon: function (subject: NamedNode, context: DataBrowserContext): HumanReadableIcon { - // Markdown files detected by extension - if (subject && isMarkdownFile(subject.uri)) { - return icons.iconBase + 'markdown.svg' - } - - // Dokieli files detected by content check - if (subject) { - const kb = context.session.store - - // Check cache from previous detection - const cachedResult = dokieliCache.get(subject.uri) - if (cachedResult === 'dokieli') { - return icons.iconBase + 'dokieli-logo.png' - } else if (cachedResult === 'html') { - return icons.originalIconBase + 'tango/22-text-x-generic.png' - } - - // Check if content already fetched (synchronous) - const responseText = kb.fetcher.getHeader(subject.doc(), 'content') - if (responseText && responseText.length > 0) { - const text = responseText[0] - const isDokieli = text.includes('" }' + const pane = renderWith('application/json', { + webOperation: vi.fn().mockResolvedValue({ responseText: source }) + }) + + await vi.waitFor(() => { + expect(pane.querySelector('solid-ui-error-state')).not.toBeNull() + }) + expect((pane.querySelector('solid-ui-error-state') as HTMLElement & { message: string }).message) + .toBe('Invalid JSON — showing the original content.') + expect(pane.querySelector('pre')?.textContent).toBe(source) + expect(pane.querySelector('.human-readable-document-status')).toHaveAttribute('data-keep-frame', 'true') + expect(pane.querySelector('script, img')).toBeNull() + }) + + it('does not report internal JSON validation errors as invalid JSON', async () => { + vi.spyOn(JSON, 'parse').mockImplementation(() => { + throw new Error('unexpected validator failure') + }) + const pane = renderWith('application/json', { + webOperation: vi.fn().mockResolvedValue({ responseText: '{"valid":true}' }) + }) + + await vi.waitFor(() => { + expect(pane.querySelector('solid-ui-error-state')).not.toBeNull() + }) + expect((pane.querySelector('solid-ui-error-state') as HTMLElement & { message: string }).message) + .toBe('Unable to validate JSON — showing the original content.') + expect(pane.querySelector('pre')?.textContent).toBe('{"valid":true}') + }) + + it('keeps long JSON available in the mobile layout', async () => { + const pane = renderWith('application/json', { + webOperation: vi.fn().mockResolvedValue({ responseText: `{"value":"${'x'.repeat(120)}"}` }) + }, { layout: 'mobile' }) + const frame = pane.querySelector('pre')! + + await vi.waitFor(() => expect(frame.textContent).toContain('x'.repeat(120))) + expect(pane).toHaveAttribute('data-layout', 'mobile') + expect(frame).toHaveClass('human-readable-json-preview') + }) + + it('uses JSON filename fallback only without a conflicting known MIME type', async () => { + const jsonPane = renderWith('', { + webOperation: vi.fn().mockResolvedValue({ responseText: '{"ok":true}' }) + }, {}, 'https://pod.example/docs/data.jsonld?download=1') + await vi.waitFor(() => expect(jsonPane.querySelector('.human-readable-json-preview')).not.toBeNull()) + + const genericMimePane = renderWith('application/octet-stream', { + webOperation: vi.fn().mockResolvedValue({ responseText: '{"ok":true}' }) + }, {}, 'https://pod.example/docs/data.json') + await vi.waitFor(() => expect(genericMimePane.querySelector('.human-readable-json-preview')).not.toBeNull()) + + const htmlPane = renderWith('text/html', { + _fetch: vi.fn().mockResolvedValue(htmlResponse('Known HTML')) + }, {}, 'https://pod.example/docs/data.json') + await waitForSrcdoc(htmlPane, 'Known HTML') + expect(htmlPane.querySelector('.human-readable-json-preview')).toBeNull() + }) + + it('renders plain text as escaped text through Lit', async () => { + const webOperation = vi.fn().mockResolvedValue({ responseText: '' }) + const pane = renderWith('text/plain', { webOperation }) await flush() - const frame = pane.querySelector('iframe')! - expect(webOperation).toHaveBeenCalledWith('GET', uri) + expect(pane.querySelector('pre')?.textContent).toBe('') + expect(pane.querySelector('script')).toBeNull() + }) + + it('makes plain text keyboard accessible in the mobile layout', () => { + const pane = renderWith('text/plain', { + webOperation: vi.fn().mockResolvedValue({ responseText: 'Text' }) + }, { layout: 'mobile' }) + const frame = pane.querySelector('pre') + + expect(pane).toHaveAttribute('data-layout', 'mobile') + expect(frame).toHaveAttribute('tabindex', '0') + expect(frame).toHaveAttribute('aria-label', 'Plain text document') + }) + + it('renders HTML from the authenticated fetch instead of letting the iframe request it', async () => { + const fetch = vi.fn().mockResolvedValue(htmlResponse('Hello')) + const pane = renderWith('text/html', { _fetch: fetch }) + await waitForSrcdoc(pane, 'Hello') + + const frame = getFrame(pane)! + expect(fetch).toHaveBeenCalledWith(uri) expect(frame.getAttribute('src')).toBeNull() expect(frame.srcdoc).toContain('Hello') expect(frame.srcdoc).toContain(``) - expect(frame.name).toBe(HUMAN_READABLE_PREVIEW_FRAME_NAME) + expect(frame.name).toBe(IFRAME_PREVIEW_FRAME_NAME) expect(frame.getAttribute('sandbox')).not.toContain('allow-same-origin') expect(pane.classList.contains('human-readable-pane--iframe')).toBe(true) expect(pane.querySelector('a')).toBeNull() }) - it('appends the resize script to HTML fragments without a closing body tag', async () => { + it('renders HTML fragments without adding a resize script', async () => { const pane = renderWith('text/html', { - webOperation: vi.fn().mockResolvedValue({ responseText: '
Fragment
' }) + _fetch: vi.fn().mockResolvedValue(htmlResponse('
Fragment
')) }) - await flush() + await waitForSrcdoc(pane, 'Fragment') - expect(pane.querySelector('iframe')?.srcdoc).toContain('solidos-preview-size') + expect(getFrame(pane)?.srcdoc).not.toContain('solidos-preview-size') }) it('labels an HTML iframe from its fetched title and falls back to its URI filename', async () => { const titled = renderWith('text/html', { - webOperation: vi.fn().mockResolvedValue({ responseText: ' A useful title ' }) + _fetch: vi.fn().mockResolvedValue(htmlResponse(' A useful title ')) }) - await flush() - expect(titled.querySelector('iframe')?.title).toBe('A useful title') + await waitForSrcdoc(titled, 'A useful title') + expect(getFrame(titled)?.title).toBe('A useful title') const untitled = renderWith('text/html', { - webOperation: vi.fn().mockResolvedValue({ responseText: 'No title' }) + _fetch: vi.fn().mockResolvedValue(htmlResponse('No title')) }) - await flush() - expect(untitled.querySelector('iframe')?.title).toBe('page.html') + await waitForSrcdoc(untitled, 'No title') + expect(getFrame(untitled)?.title).toBe('page.html') }) it('keeps Dokieli documents isolated and mediates same-origin reads plus exact-document writes', async () => { const dokieliUri = `${window.location.origin}/docs/dok.html` const html = '

Dok

' - const authenticatedFetch = vi.fn().mockResolvedValue(new Response('ok')) + const authenticatedFetch = vi.fn().mockImplementation((_url, init) => + Promise.resolve(init ? new Response('ok') : htmlResponse(html))) const subject = { uri: dokieliUri, doc: () => subject } const store = { fetcher: { getHeader: vi.fn().mockReturnValue(['text/html']), - webOperation: vi.fn().mockResolvedValue({ responseText: html }), _fetch: authenticatedFetch } } const pane = humanReadablePane.render(subject as any, { dom: document, session: { store } } as any) document.body.appendChild(pane) - const frame = pane.querySelector('iframe')! try { - await flush() + await waitForSrcdoc(pane, 'solidos-preview-request') + const frame = getFrame(pane)! + // jsdom does not create browsing contexts for iframes in shadow roots. + Object.defineProperty(frame, 'contentWindow', { configurable: true, value: window }) + authenticatedFetch.mockClear() expect(frame.getAttribute('sandbox')).toBe('allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-modals') expect(frame.srcdoc).toContain('solidos-preview-request') expect(frame.srcdoc).toContain('dokieli.js') @@ -269,7 +459,7 @@ describe('human readable pane iframe rendering', () => { body: 'saved from file srcdoc' }) authenticatedFetch.mockClear() - const postToPreview = vi.spyOn(frame.contentWindow!, 'postMessage') + const postToPreview = vi.spyOn(window, 'postMessage') window.dispatchEvent(new MessageEvent('message', { source: frame.contentWindow, data: { @@ -289,19 +479,31 @@ describe('human readable pane iframe rendering', () => { ok: false, status: 403 }), '*') + pane.remove() + window.dispatchEvent(new MessageEvent('message', { + source: window, + data: { + type: 'solidos-preview-request', + nonce: frame.srcdoc.match(/const nonce = "([^"]+)"/)?.[1], + id: 'after-removal', + url: dokieliUri, + method: 'PUT', + body: 'x' + } + })) + await flush() + expect(authenticatedFetch).not.toHaveBeenCalled() } finally { pane.remove() } }) it('keeps cross-origin Dokieli documents in the isolated preview', async () => { - const webOperation = vi.fn().mockResolvedValue({ - responseText: '' - }) - const pane = renderWith('text/html', { webOperation }) - await flush() + const fetch = vi.fn().mockResolvedValue(htmlResponse('')) + const pane = renderWith('text/html', { _fetch: fetch }) + await waitForSrcdoc(pane, 'dokieli.js') - const frame = pane.querySelector('iframe')! + const frame = getFrame(pane)! expect(frame.getAttribute('sandbox')).toBe('allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-modals') expect(frame.srcdoc).toContain('dokieli.js') }) @@ -311,9 +513,9 @@ describe('human readable pane iframe rendering', () => { headers: { 'content-type': 'text/html; charset=utf-8' } }) const pane = renderWith('image/png', { _fetch: vi.fn().mockResolvedValue(response) }) - await flush() + await waitForSrcdoc(pane, 'compromised') - const frame = pane.querySelector('iframe')! + const frame = getFrame(pane)! expect(frame.getAttribute('sandbox')).toBe('allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-modals') expect(frame.src).toBe('') expect(frame.srcdoc).toContain('compromised') @@ -325,9 +527,9 @@ describe('human readable pane iframe rendering', () => { headers: { 'content-type': 'application/pdf' } }) const pane = renderWith('application/octet-stream', { _fetch: vi.fn().mockResolvedValue(response) }) - await flush() + await vi.waitFor(() => expect(getFrame(pane)?.src).toBe('blob:https://pod.example/resource')) - const frame = pane.querySelector('iframe')! + const frame = getFrame(pane)! expect(frame.getAttribute('sandbox')).toBeNull() expect(frame.src).toBe('blob:https://pod.example/resource') expect(createObjectURL).toHaveBeenCalled() @@ -340,20 +542,21 @@ describe('human readable pane iframe rendering', () => { headers: { 'content-type': 'image/svg+xml' } }) const pane = renderWith('image/svg+xml', { _fetch: vi.fn().mockResolvedValue(response) }) - await flush() + await vi.waitFor(() => expect(createObjectURL).toHaveBeenCalled()) - expect(pane.querySelector('iframe')?.getAttribute('sandbox')) + expect(getFrame(pane)?.getAttribute('sandbox')) .toBe('allow-scripts allow-forms allow-popups allow-popups-to-escape-sandbox allow-modals') createObjectURL.mockRestore() }) - it('revokes a blob URL when the preview is removed before fetching completes', async () => { + it('does not create a blob URL when the preview is removed before fetching completes', async () => { let resolveResponse!: (response: Response) => void const responsePromise = new Promise(resolve => { resolveResponse = resolve }) const createObjectURL = vi.spyOn(URL, 'createObjectURL').mockReturnValue('blob:https://pod.example/resource') const revokeObjectURL = vi.spyOn(URL, 'revokeObjectURL').mockImplementation(() => {}) - const pane = renderWith('application/pdf', { _fetch: vi.fn().mockReturnValue(responsePromise) }) - document.body.appendChild(pane) + const fetch = vi.fn().mockReturnValue(responsePromise) + const pane = renderWith('application/pdf', { _fetch: fetch }) + await vi.waitFor(() => expect(fetch).toHaveBeenCalled()) pane.remove() resolveResponse(new Response('pdf', { headers: { 'content-type': 'application/pdf' } @@ -361,24 +564,109 @@ describe('human readable pane iframe rendering', () => { await flush() await flush() - expect(createObjectURL).toHaveBeenCalled() - expect(revokeObjectURL).toHaveBeenCalledWith('blob:https://pod.example/resource') + expect(createObjectURL).not.toHaveBeenCalled() + expect(revokeObjectURL).not.toHaveBeenCalled() createObjectURL.mockRestore() revokeObjectURL.mockRestore() }) - it('shows an error instead of the resource URL when the fetch fails', async () => { - const webOperation = vi.fn().mockRejectedValue(new Error('401')) - vi.spyOn(console, 'error').mockImplementation(() => {}) - const pane = renderWith('text/html', { webOperation }) + it('renders the PDF viewer without an iframe or blob URL', async () => { + const pane = renderWith('application/pdf', { + _fetch: vi.fn().mockResolvedValue(new Response('pdf', { headers: { 'content-type': 'application/pdf' } })) + }) + const preview = pane.querySelector('solid-panes-pdf-viewer') as HTMLElement & { + pdfData?: ArrayBuffer + } + await vi.waitFor(() => expect(preview.pdfData).toBeInstanceOf(ArrayBuffer)) + expect(pane.querySelector('iframe')).toBeNull() + const main = preview.shadowRoot?.querySelector('.main') + expect(main).toHaveAttribute('tabindex', '0') + expect(main).toHaveAttribute('aria-describedby', 'pdf-preview-description') + expect(preview.shadowRoot?.querySelector('#pdf-preview-description')?.textContent) + .toContain('PDF text and links are not accessible in this preview') + expect(preview.shadowRoot?.querySelector('.canvas')).toHaveAttribute('role', 'img') + }) + + it('passes the pane registry mobile layout to the PDF viewer', () => { + const pane = renderWith('application/pdf', { _fetch: vi.fn() }, { layout: 'mobile' }) + expect(pane.querySelector('solid-panes-pdf-viewer')).toHaveAttribute('data-layout', 'mobile') + }) + + it('loads a changed subject and ignores the earlier response', async () => { + let resolveFirst!: (response: Response) => void + const firstResponse = new Promise(resolve => { resolveFirst = resolve }) + const fetch = vi.fn() + .mockReturnValueOnce(firstResponse) + .mockResolvedValueOnce(htmlResponse('

New document

')) + const pane = renderWith('text/html', { _fetch: fetch }) + await vi.waitFor(() => expect(fetch).toHaveBeenCalledWith(uri)) + + const preview = pane.querySelector('solid-panes-iframe-preview') as IframePreview + const nextUri = 'https://pod.example/docs/next.html' + preview.subject = sym(nextUri) + await waitForSrcdoc(pane, 'New document') + expect(fetch).toHaveBeenCalledWith(nextUri) + + resolveFirst(htmlResponse('

Stale document

')) + await flush() + expect(getFrame(pane)?.srcdoc).toContain('New document') + expect(getFrame(pane)?.srcdoc).not.toContain('Stale document') + }) + + it('clears an old srcdoc when switching to a blob preview', async () => { + const fetch = vi.fn() + .mockResolvedValueOnce(htmlResponse('HTML preview')) + .mockResolvedValueOnce(new Response('binary', { headers: { 'content-type': 'application/octet-stream' } })) + const pane = renderWith('text/html', { _fetch: fetch }) + const preview = pane.querySelector('solid-panes-iframe-preview') as IframePreview + await waitForSrcdoc(pane, 'HTML preview') + + vi.spyOn(URL, 'createObjectURL').mockReturnValue('blob:https://pod.example/next') + preview.subject = sym('https://pod.example/docs/next.bin') + await vi.waitFor(() => expect(getFrame(pane)?.src).toBe('blob:https://pod.example/next')) + + expect(getFrame(pane)?.getAttribute('srcdoc')).toBeNull() + vi.restoreAllMocks() + }) + + it.each(['text/html', 'application/octet-stream'])('does not attach a late Dokieli bridge after a %s preview is removed', async contentType => { + let resolveResponse!: (response: Response) => void + const responsePromise = new Promise(resolve => { resolveResponse = resolve }) + const fetch = vi.fn().mockReturnValue(responsePromise) + const pane = renderWith(contentType, { + _fetch: fetch + }) + await vi.waitFor(() => expect(fetch).toHaveBeenCalled()) + const frame = getFrame(pane)! + pane.remove() + const addListener = vi.spyOn(window, 'addEventListener') + const html = '' + resolveResponse(htmlResponse(html)) await flush() + expect(frame.srcdoc).toBe('') + expect(addListener).not.toHaveBeenCalledWith('message', expect.any(Function)) + addListener.mockRestore() + }) - const frame = pane.querySelector('iframe')! + it('shows an error instead of the resource URL when the fetch fails', async () => { + const fetch = vi.fn().mockRejectedValue(new Error('401')) + const pane = renderWith('text/html', { _fetch: fetch }) + const preview = pane.querySelector('solid-panes-iframe-preview')! + await vi.waitFor(() => expect(preview.shadowRoot?.querySelector('solid-ui-error-state')).not.toBeNull()) + + const frame = getFrame(pane)! expect(frame.getAttribute('src')).toBeNull() - expect(frame.srcdoc).toContain('Error loading content') + expect(preview.shadowRoot?.querySelector('solid-ui-error-state')).toHaveProperty('message', '401') + + preview.shadowRoot?.querySelector('solid-ui-error-state')?.dispatchEvent(new CustomEvent('close', { + bubbles: true, + composed: true + })) + await flush() + expect(preview.shadowRoot?.querySelector('solid-ui-error-state')).toBeNull() }) - it('falls back to the encoded filename when it is not valid UTF-8', () => { + it('falls back to the encoded filename when it is not valid UTF-8', async () => { const invalidUri = 'https://pod.example/docs/file%FF.pdf' const subject = { uri: invalidUri, doc: () => subject } const store = { @@ -390,8 +678,10 @@ describe('human readable pane iframe rendering', () => { } } const pane = humanReadablePane.render(subject as any, { dom: document, session: { store } } as any) - - expect(pane.querySelector('iframe')?.title).toBe('file%FF.pdf') + document.body.appendChild(pane) + await vi.waitFor(() => expect( + pane.querySelector('solid-panes-pdf-viewer')?.shadowRoot?.querySelector('section') + ).toHaveAttribute('aria-label', 'Preview of file%FF.pdf')) }) it('gives Dokieli the signed-in viewer as a bridged session', async () => { @@ -403,14 +693,14 @@ describe('human readable pane iframe rendering', () => { const store = { fetcher: { getHeader: vi.fn().mockReturnValue(['text/html']), - webOperation: vi.fn().mockResolvedValue({ responseText: html }), - _fetch: vi.fn() + _fetch: vi.fn().mockImplementation(() => Promise.resolve(htmlResponse(html))) } } try { const pane = humanReadablePane.render(subject as any, { dom: document, session: { store } } as any) - await flush() - const srcdoc = pane.querySelector('iframe')!.srcdoc + document.body.appendChild(pane) + await waitForSrcdoc(pane, 'const viewerWebId') + const srcdoc = getFrame(pane)!.srcdoc expect(srcdoc).toContain(`const viewerWebId = ${JSON.stringify(webId)}`) expect(srcdoc).toContain('if (bridgedSession) config.Session = bridgedSession') expect(srcdoc).toContain('Object.defineProperty(config, \'DocumentURL\'') @@ -418,8 +708,9 @@ describe('human readable pane iframe rendering', () => { spy.mockReturnValue(null) const loggedOut = humanReadablePane.render(subject as any, { dom: document, session: { store } } as any) - await flush() - expect(loggedOut.querySelector('iframe')!.srcdoc).toContain('const viewerWebId = null') + document.body.appendChild(loggedOut) + await waitForSrcdoc(loggedOut, 'const viewerWebId') + expect(getFrame(loggedOut)!.srcdoc).toContain('const viewerWebId = null') } finally { spy.mockRestore() } diff --git a/test/unit/mainPage/index.test.ts b/test/unit/mainPage/index.test.ts index 7778b4f9..2fcc2912 100644 --- a/test/unit/mainPage/index.test.ts +++ b/test/unit/mainPage/index.test.ts @@ -148,6 +148,24 @@ describe('main page load', () => { expect(GotoSubject.mock.calls[0][2]).toBeUndefined() expect(window.history.state).toEqual({}) }) + + it('loads the resource requested by a SolidOS deep link', async () => { + const GotoSubject = setup({}, false) + const resourceUri = 'https://pod.example/docs/readme.md' + window.history.replaceState({}, '', `/?uri=${encodeURIComponent(resourceUri)}`) + + await initMainPage(store) + + expect(GotoSubject).toHaveBeenCalledWith( + store.sym(resourceUri), + true, + undefined, + true, + undefined, + undefined, + expect.anything() + ) + }) }) describe('browser navigation without a reload', () => { diff --git a/test/unit/markdownPreview.test.ts b/test/unit/markdownPreview.test.ts new file mode 100644 index 00000000..7545de85 --- /dev/null +++ b/test/unit/markdownPreview.test.ts @@ -0,0 +1,61 @@ +import { afterEach, describe, expect, it, vi } from 'vitest' +import { renderMarkdownContent } from '../../src/humanReadable/markdownPreview' + +const subject = { uri: 'https://pod.example/docs/readme.md' } as any + +function createFrame () { + const frame = document.createElement('div') + document.body.appendChild(frame) + return frame +} + +afterEach(() => { + document.body.replaceChildren() + vi.restoreAllMocks() +}) + +describe('renderMarkdownContent', () => { + it('renders Markdown and removes raw HTML', async () => { + const frame = createFrame() + const status = document.createElement('div') + document.body.appendChild(status) + const store = { + fetcher: { + webOperation: vi.fn().mockResolvedValue({ + responseText: '# Heading\n\n\n\n**bold**' + }) + } + } + + renderMarkdownContent(store as any, subject, frame, status) + + await vi.waitFor(() => { + expect(frame.querySelector('h1')?.textContent).toBe('Heading') + }) + expect(frame.querySelector('strong')?.textContent).toBe('bold') + expect(frame.querySelector('script')).toBeNull() + expect(frame).toHaveClass('human-readable-document-frame', 'human-readable-markdown-preview') + expect(store.fetcher.webOperation).toHaveBeenCalledWith('GET', subject.uri) + }) + + it('shows an error when Markdown cannot be fetched', async () => { + const frame = createFrame() + const status = document.createElement('div') + document.body.appendChild(status) + const store = { + fetcher: { + webOperation: vi.fn().mockRejectedValue(new Error('network failure')) + } + } + + renderMarkdownContent(store as any, subject, frame, status) + + await vi.waitFor(() => { + expect(status.querySelector('solid-ui-error-state')).not.toBeNull() + }) + await vi.waitFor(() => { + expect(status.querySelector('solid-ui-error-state')?.shadowRoot?.textContent) + .toContain('The document could not be loaded.') + }) + }) +}) diff --git a/test/unit/navigation/controller.test.ts b/test/unit/navigation/controller.test.ts index 0bf69eaf..d6c313b4 100644 --- a/test/unit/navigation/controller.test.ts +++ b/test/unit/navigation/controller.test.ts @@ -209,6 +209,15 @@ describe('restoring a history entry', () => { expect(refreshHeading).toHaveBeenCalledWith(false) }) + it('restores a cross-origin resource from a ?uri= deep link', async () => { + const target = 'https://other.example/private/document.html' + window.history.replaceState({}, '', `/?uri=${encodeURIComponent(target)}`) + + await controller.show({ kind: 'restore' }) + + expect(GotoSubject.mock.calls[0][0]).toEqual(store.sym(target)) + }) + it('still shows the default view when the entry names a pane that cannot be built', async () => { getFolderPane.mockResolvedValue(null) window.history.replaceState({ paneName: 'folder', paneUri: 'https://pod.example/timea/' }, '', '/timea2/docs/') diff --git a/test/unit/slideshowPane.test.ts b/test/unit/slideshowPane.test.ts index 0b2bd448..ea07ce8f 100644 --- a/test/unit/slideshowPane.test.ts +++ b/test/unit/slideshowPane.test.ts @@ -24,9 +24,25 @@ function contextFor (contents: Array<{ uri: string, image?: boolean }>) { } describe('slideshow pane', () => { - it('requires at least two images', () => { + it('offers Slideshow for a container with one image', () => { const { subject, context } = contextFor([{ uri: 'one.png', image: true }]) + expect(slideshowPane.label(subject as any, context)).toBe('Slideshow') + }) + + it.each([ + { contents: [] }, + { contents: [{ uri: 'notes.txt', image: false }] } + ])('does not offer Slideshow without images: $contents', ({ contents }) => { + const { subject, context } = contextFor(contents) + + expect(slideshowPane.label(subject as any, context)).toBeNull() + }) + + it('does not offer Slideshow for an individual image resource', () => { + const { subject, context } = contextFor([{ uri: 'one.png', image: true }]) + resource.isContainer.mockReturnValueOnce(false) + expect(slideshowPane.label(subject as any, context)).toBeNull() }) diff --git a/typings/pdf-worker-url.d.ts b/typings/pdf-worker-url.d.ts new file mode 100644 index 00000000..8a522cd6 --- /dev/null +++ b/typings/pdf-worker-url.d.ts @@ -0,0 +1,4 @@ +declare module 'pdfjs-dist/build/pdf.worker.min.mjs?url' { + const workerUrl: string + export default workerUrl +}