Compare commits
34
Commits
1a8e667944
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
819d9cb77d | ||
|
|
5b685e251b | ||
|
|
0d61c7662a | ||
|
|
ed2fd9f45e | ||
|
|
7f8091120c | ||
|
|
05adc4574a | ||
|
|
0d14e6a6d8 | ||
|
|
b4ae405876 | ||
|
|
1c174a3b1c | ||
|
|
c3e2bbe4c0 | ||
|
|
ac7b41ecfc | ||
|
|
52c1f80d4b | ||
|
|
cd899df541 | ||
|
|
4184484825 | ||
|
|
b700ef73ad | ||
|
|
0598e0c6bd | ||
|
|
30e4d5c87e | ||
|
|
a55a5f6b06 | ||
|
|
291eb3dbce | ||
|
|
ac53680831 | ||
|
|
3b0918311b | ||
|
|
1afb6b664f | ||
|
|
74730206bf | ||
|
|
073c6e402e | ||
|
|
e1b7961f45 | ||
|
|
f72b7f2f56 | ||
|
|
c4c2c54d23 | ||
|
|
f44cb83657 | ||
|
|
7a0b49364f | ||
|
|
e4d4d11413 | ||
|
|
b620536eb8 | ||
|
|
ad4b21daf1 | ||
|
|
0f9faa45f0 | ||
|
|
2809dc6295 |
No files matched your search
+8
-7
@@ -1,10 +1,11 @@
|
|||||||
{
|
{
|
||||||
"useTabs": false,
|
"useTabs": false,
|
||||||
"singleQuote": true,
|
"bracketSameLine": true,
|
||||||
"trailingComma": "es5",
|
"singleQuote": true,
|
||||||
"printWidth": 100,
|
"trailingComma": "es5",
|
||||||
"plugins": ["prettier-plugin-svelte"],
|
"printWidth": 100,
|
||||||
"pluginSearchDirs": ["."],
|
"plugins": ["prettier-plugin-svelte"],
|
||||||
|
"pluginSearchDirs": ["."],
|
||||||
"semi": false,
|
"semi": false,
|
||||||
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
|
"overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }]
|
||||||
}
|
}
|
||||||
@@ -2,14 +2,40 @@
|
|||||||
|
|
||||||
> A no-database, no-backend pastebin-like service. All the data is stored in the url.
|
> A no-database, no-backend pastebin-like service. All the data is stored in the url.
|
||||||
|
|
||||||
This is a rewrite of https://nopaste.boris.sh/, which was a rewrite of https://topaz.github.io/paste/. The biggest improvement of this version is that it uses brotli compression, while staying compatible with the original lzma compressed urls.
|
This is a rewrite of https://nopaste.boris.sh/, which is a rewrite of https://topaz.github.io/paste/
|
||||||
|
|
||||||
[More information on this self-hosted "about" page](https://paste.scambier.xyz/?l=mrwn#G14EICwPbMc0BJ69xNPoItLoErDRMwMj3+vxE5RxArxajeByk+b0b1Tm2h/5ugGgK6S83AqUCi09HeYmDs+vvzQc0QDZe7v7U2rHnFe6CTWSm2AArNua4tqtXVIEFVQuqG+is15etOm1OZOPPCH4xDX1iDNF2bQcN9ugum0Icnwj51n0nlvNacn/N3OOctSGrQbLoNzG8n5bSoJQXOx+PsxV+MeUl+rkKNPIAXT9c8LoOY/772FiFkLv/5w8rvtCBc38VEE5lzmGFcZ0QtqlzBhvWLV5WPhRkROqeoKoDCtH03/fQVI5Y8HfLkq2/Nuidd1GQTKgmPJQVWbZ4cAiqUdOJG6j6pvu48qWjqamYG3nFPHcdYLHYCRV877U2mBgSHTbLWv6eu/DEA88SE5XEIqiQFyDVS2HLN7jJSloLHQJ+jOE86zb9jrkQ9tXAwkAoovCcnlrW5T/EU4L7imRsDAkZdEySO/ri/NBuHPMpSFnqGItLlPd98/SZSmySbImOLfv4WGbdCxw9TYykGsk56aQaVSa/DB2t5HfD6x28lJVlMm3Hjnkwyx95PxNGH0teCAk6CqtbBYlC3LjhY0IEpJ0WWZWY6MlJB+jEW7lAN3DSJD0QFz2FZOOV/HwA9LbFBU=)
|
[More information on this self-hosted "about" page](https://paste.scambier.xyz/about)
|
||||||
|
|
||||||
|
## Maximum lengths for links
|
||||||
|
|
||||||
|
NoPaste is great for sharing code snippets on various platforms.
|
||||||
|
|
||||||
|
These are the maximum link lengths on some apps and browsers.
|
||||||
|
|
||||||
|
| App | Max length | Notes |
|
||||||
|
| -------- | ---------- | --------------------------------------------------------------------------------- |
|
||||||
|
| Mastodon | None? | Not specified in the docs |
|
||||||
|
| Reddit | 10,000 | |
|
||||||
|
| Twitter | 4,088 | |
|
||||||
|
| Slack | 4,000 | |
|
||||||
|
| Discord | 4,000 | 4,000 is the whole message limit. Longer messages are converted into attachements |
|
||||||
|
| QR Code | 2,610 | |
|
||||||
|
| Bitly | 2,048 | |
|
||||||
|
|
||||||
|
| Browser | Max length | Notes |
|
||||||
|
| --------------- | ------------------------- | --------------------------------------- |
|
||||||
|
| Google Chrome | (win) 32,779 (mac) 10,000 | Will not display, but larger links work |
|
||||||
|
| Firefox | >64,000 | |
|
||||||
|
| Microsoft Edge | 2,083 | Anything over 2083 will fail |
|
||||||
|
| Android | 8,192 | |
|
||||||
|
| Safari | Lots | |
|
||||||
|
|
||||||
|
The safest limit to make sure your Paste link works everywhere seems to be 2,083.
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
- [x] Use brotli
|
- [x] Use brotli
|
||||||
- [x] Stay compatible with original lzma-compressed urls
|
- [x] ~~Stay compatible with original lzma-compressed urls~~
|
||||||
- [x] Have a read-only view with nice colors for code blocks
|
- [x] Have a read-only view with nice colors for code blocks
|
||||||
- [ ] Use CodeMirror 6
|
- [ ] Use CodeMirror 6
|
||||||
- [ ] 100% self-contained, no dependance on jsdeliver
|
- [ ] 100% self-contained, no dependance on jsdeliver
|
||||||
@@ -23,4 +49,4 @@ $ pnpm build
|
|||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
GNU GPLv3
|
GNU GPLv3
|
||||||
+31
-30
@@ -12,43 +12,44 @@
|
|||||||
"format": "prettier --plugin-search-dir . --write ."
|
"format": "prettier --plugin-search-dir . --write ."
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@sveltejs/adapter-auto": "^2.0.0",
|
"@sveltejs/adapter-auto": "^2.1.1",
|
||||||
"@sveltejs/kit": "^1.20.4",
|
"@sveltejs/kit": "^1.30.4",
|
||||||
"@tailwindcss/typography": "^0.5.10",
|
"@tailwindcss/typography": "^0.5.16",
|
||||||
"@types/codemirror": "^5.60.12",
|
"@types/codemirror": "^5.60.16",
|
||||||
"@types/lodash-es": "^4.17.10",
|
"@types/lodash-es": "^4.17.12",
|
||||||
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
||||||
"@typescript-eslint/parser": "^6.0.0",
|
"@typescript-eslint/parser": "^6.21.0",
|
||||||
"autoprefixer": "^10.4.16",
|
"autoprefixer": "^10.4.21",
|
||||||
"eslint": "^8.28.0",
|
"eslint": "^8.57.1",
|
||||||
"eslint-config-prettier": "^8.5.0",
|
"eslint-config-prettier": "^8.10.2",
|
||||||
"eslint-plugin-svelte": "^2.30.0",
|
"eslint-plugin-svelte": "^2.46.1",
|
||||||
"postcss": "^8.4.31",
|
"postcss": "^8.5.6",
|
||||||
"prettier": "^2.8.0",
|
"prettier": "^2.8.8",
|
||||||
"prettier-plugin-svelte": "^2.10.1",
|
"prettier-plugin-svelte": "^2.10.1",
|
||||||
"svelte": "^4.0.5",
|
"svelte": "^4.2.20",
|
||||||
"svelte-check": "^3.4.3",
|
"svelte-check": "^3.8.6",
|
||||||
"tailwindcss": "^3.3.5",
|
"tailwindcss": "^3.4.17",
|
||||||
"tslib": "^2.4.1",
|
"tslib": "^2.8.1",
|
||||||
"typescript": "^5.0.0",
|
"typescript": "^5.9.2",
|
||||||
"vite": "^4.4.2"
|
"vite": "^4.5.14"
|
||||||
},
|
},
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@iconify/svelte": "^3.1.4",
|
"@iconify/svelte": "^3.1.6",
|
||||||
"@svelte-put/clickoutside": "^3.0.0",
|
"@svelte-put/clickoutside": "^3.0.2",
|
||||||
"@sveltejs/adapter-static": "^2.0.3",
|
"@sveltejs/adapter-static": "^2.0.3",
|
||||||
"brotli-compress": "^1.3.3",
|
"brotli-compress": "^1.3.3",
|
||||||
"highlight.js": "^11.9.0",
|
"highlight.js": "^11.11.1",
|
||||||
"lodash-es": "^4.17.21",
|
"lodash-es": "^4.17.21",
|
||||||
"rehype-highlight": "^7.0.0",
|
"rehype-highlight": "^7.0.2",
|
||||||
"rehype-stringify": "^10.0.0",
|
"rehype-stringify": "^10.0.1",
|
||||||
|
"remark-gfm": "^4.0.1",
|
||||||
"remark-parse": "^11.0.0",
|
"remark-parse": "^11.0.0",
|
||||||
"remark-rehype": "^11.0.0",
|
"remark-rehype": "^11.1.2",
|
||||||
"sass": "^1.69.5",
|
"sass": "^1.91.0",
|
||||||
"slim-select": "^2.6.0",
|
"slim-select": "^2.12.1",
|
||||||
"svelte-select": "^5.7.0",
|
"svelte-select": "^5.8.3",
|
||||||
"tw-elements": "^1.0.0",
|
"tw-elements": "^1.1.0",
|
||||||
"unified": "^11.0.4"
|
"unified": "^11.0.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Generated
+2967
-1991
File diff suppressed because it is too large.
Load diff
Vendored
+7
-7
@@ -1,12 +1,12 @@
|
|||||||
// See https://kit.svelte.dev/docs/types#app
|
// See https://kit.svelte.dev/docs/types#app
|
||||||
// for information about these interfaces
|
// for information about these interfaces
|
||||||
declare global {
|
declare global {
|
||||||
namespace App {
|
namespace App {
|
||||||
// interface Error {}
|
// interface Error {}
|
||||||
// interface Locals {}
|
// interface Locals {}
|
||||||
// interface PageData {}
|
// interface PageData {}
|
||||||
// interface Platform {}
|
// interface Platform {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export {};
|
export {}
|
||||||
+9
-19
@@ -3,29 +3,19 @@
|
|||||||
<head>
|
<head>
|
||||||
<title>Paste</title>
|
<title>Paste</title>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<link rel="icon" href="%sveltekit.assets%/favicon.ico" />
|
<link rel="icon" href="%sveltekit.assets%/favicon.svg" />
|
||||||
<link rel="stylesheet" type="text/css" href="%sveltekit.assets%/fonts.css" />
|
<link rel="stylesheet" href="%sveltekit.assets%/hack-subset.css" />
|
||||||
<link
|
|
||||||
rel="stylesheet"
|
|
||||||
type="text/css"
|
|
||||||
href="https://cdn.jsdelivr.net/combine/
|
|
||||||
npm/codemirror@5.65.16/lib/codemirror.min.css,
|
|
||||||
npm/codemirror@5.65.16/theme/nord.min.css"
|
|
||||||
/>
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<meta property="og:title" content="Paste - No-database paste service" />
|
||||||
|
<meta property="og:url" content="https://paste.scambier.xyz" />
|
||||||
|
<meta property="og:type" content="website" />
|
||||||
|
<meta
|
||||||
|
name="description"
|
||||||
|
property="og:description"
|
||||||
|
content="Paste is a client-side paste service with no database, and no back-end code. The data is stored entirely in the shared link" />
|
||||||
%sveltekit.head%
|
%sveltekit.head%
|
||||||
</head>
|
</head>
|
||||||
<body data-sveltekit-preload-data="hover">
|
<body data-sveltekit-preload-data="hover">
|
||||||
<div class="dark:text-gray-300 dark:bg-gray-800 min-h-screen">%sveltekit.body%</div>
|
<div class="dark:text-gray-300 dark:bg-gray-800 min-h-screen">%sveltekit.body%</div>
|
||||||
|
|
||||||
<script src="https://cdn.jsdelivr.net/combine/
|
|
||||||
npm/lzma@2.3.2/src/lzma.min.js,
|
|
||||||
npm/codemirror@5.65.16,
|
|
||||||
npm/codemirror@5.65.16/addon/mode/loadmode.min.js,
|
|
||||||
npm/codemirror@5.65.16/addon/mode/overlay.min.js,
|
|
||||||
npm/codemirror@5.65.16/addon/mode/multiplex.min.js,
|
|
||||||
npm/codemirror@5.65.16/addon/mode/simple.min.js,
|
|
||||||
npm/codemirror@5.65.16/addon/scroll/simplescrollbars.js,
|
|
||||||
npm/codemirror@5.65.16/mode/meta.min.js"></script>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import Icon from '@iconify/svelte'
|
||||||
|
import { fade } from 'svelte/transition'
|
||||||
|
|
||||||
|
export let isMarkdown: boolean
|
||||||
|
export let isPlainText: boolean
|
||||||
|
export let decompressed: string
|
||||||
|
export let htmlContent: string
|
||||||
|
let cssClass = ''
|
||||||
|
export { cssClass as class }
|
||||||
|
|
||||||
|
let copied = false
|
||||||
|
function copyCode() {
|
||||||
|
navigator.clipboard.writeText(decompressed)
|
||||||
|
copied = true
|
||||||
|
setTimeout(() => (copied = false), 500)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class={cssClass + ' relative'}>
|
||||||
|
{#if isMarkdown}
|
||||||
|
<div class="h-full p-2">
|
||||||
|
{@html htmlContent}
|
||||||
|
</div>
|
||||||
|
{:else if isPlainText}
|
||||||
|
<pre class="h-full">{decompressed}</pre>
|
||||||
|
{:else}
|
||||||
|
<button
|
||||||
|
class="z-40 right-4 top-[5.25rem] absolute inline"
|
||||||
|
on:click={copyCode}
|
||||||
|
title="Copy code">
|
||||||
|
<Icon class="text-xl" icon="fluent:copy-24-regular" />
|
||||||
|
</button>
|
||||||
|
{#if copied}
|
||||||
|
<span class="absolute right-4 top-24" out:fade={{ duration: 500 }}>Copied!</span>
|
||||||
|
{/if}
|
||||||
|
<!-- code block -->
|
||||||
|
<pre class="h-full"><code>{@html htmlContent}</code></pre>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
@@ -62,12 +62,10 @@
|
|||||||
type="text"
|
type="text"
|
||||||
bind:value={filter}
|
bind:value={filter}
|
||||||
bind:this={inputFilter}
|
bind:this={inputFilter}
|
||||||
class={$$restProps.class ?? ''}
|
class={$$restProps.class ?? ''} />
|
||||||
/>
|
|
||||||
<div
|
<div
|
||||||
class="absolute top-full left-0 w-full bg-gray-700 max-h-[90vh] overflow-y-auto"
|
class="absolute top-full left-0 w-full bg-gray-700 max-h-[90vh] overflow-y-auto"
|
||||||
bind:this={divContainer}
|
bind:this={divContainer}>
|
||||||
>
|
|
||||||
{#each filteredItems as item}
|
{#each filteredItems as item}
|
||||||
<div class="p-1 hover:bg-gray-600" on:click={() => selectItem(item)}>{item.text}</div>
|
<div class="p-1 hover:bg-gray-600" on:click={() => selectItem(item)}>{item.text}</div>
|
||||||
{/each}
|
{/each}
|
||||||
@@ -78,8 +76,7 @@
|
|||||||
readonly
|
readonly
|
||||||
value={value?.text ?? ''}
|
value={value?.text ?? ''}
|
||||||
class={$$restProps.class ?? ''}
|
class={$$restProps.class ?? ''}
|
||||||
on:click={showOptions}
|
on:click={showOptions} />
|
||||||
/>
|
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,174 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { onMount, tick } from 'svelte'
|
||||||
|
import { shorten, getLangFromUrl } from '$lib/utils'
|
||||||
|
import type { Editor } from 'codemirror'
|
||||||
|
import { shareUrl, selectedLang } from '../store'
|
||||||
|
import ComboBox from './ComboBox.svelte'
|
||||||
|
import Icon from '@iconify/svelte'
|
||||||
|
import { goto } from '$app/navigation'
|
||||||
|
import hljs from 'highlight.js'
|
||||||
|
|
||||||
|
type Language = {
|
||||||
|
text: string
|
||||||
|
value: string
|
||||||
|
data: { mime: string; mode: string }
|
||||||
|
}
|
||||||
|
|
||||||
|
let cssClass = ''
|
||||||
|
export { cssClass as class }
|
||||||
|
export let editor: Editor | null = null
|
||||||
|
export let updateShareUrl: () => Promise<void>
|
||||||
|
|
||||||
|
let languages: Language[] = []
|
||||||
|
let selectedLanguage: Language | null = null
|
||||||
|
let textWrap = false
|
||||||
|
|
||||||
|
let urlInput: HTMLInputElement
|
||||||
|
let isUrlInputVisible = false
|
||||||
|
|
||||||
|
onMount(() => {
|
||||||
|
$selectedLang = getLangFromUrl()
|
||||||
|
selectedLanguage = languages.find((e) => e.value === $selectedLang)!
|
||||||
|
})
|
||||||
|
|
||||||
|
selectedLang.subscribe((lang) => {
|
||||||
|
textWrap = lang === 'plaintext' || lang === 'markdown'
|
||||||
|
})
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if (editor) {
|
||||||
|
// Line wrapping
|
||||||
|
editor.setOption('lineWrapping', textWrap)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$: {
|
||||||
|
if (editor) {
|
||||||
|
languages = (CodeMirror.modeInfo as unknown[])
|
||||||
|
.map((e: any) => {
|
||||||
|
let name = e.name
|
||||||
|
if (name === 'Common Lisp') name = 'Lisp'
|
||||||
|
return {
|
||||||
|
text: name,
|
||||||
|
value: shorten(name),
|
||||||
|
data: { mime: e.mime, mode: e.mode },
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.filter((l: any) => l.value !== 'gflm') // Remove github flavored markdown, redundant with markdown
|
||||||
|
|
||||||
|
selectedLanguage =
|
||||||
|
selectedLanguage ??
|
||||||
|
languages.find((e) => e.value === $selectedLang) ??
|
||||||
|
languages.find((e) => e.value === 'plt')!
|
||||||
|
|
||||||
|
const langData = selectedLanguage?.data ?? { mime: null, mode: null }
|
||||||
|
// @ts-ignore
|
||||||
|
editor.setOption('mode', langData.mime)
|
||||||
|
CodeMirror.autoLoadMode(editor, langData.mode)
|
||||||
|
$selectedLang = selectedLanguage?.value ?? 'plt'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function showUrlInput() {
|
||||||
|
// Make sure the url is up to date
|
||||||
|
await updateShareUrl()
|
||||||
|
isUrlInputVisible = true
|
||||||
|
await tick()
|
||||||
|
urlInput.value = $shareUrl
|
||||||
|
urlInput.select()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function showMarkdownLink() {
|
||||||
|
await updateShareUrl()
|
||||||
|
isUrlInputVisible = true
|
||||||
|
await tick()
|
||||||
|
urlInput.value = `[Paste snippet](${$shareUrl})`
|
||||||
|
urlInput.select()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function showIframeCode() {
|
||||||
|
await updateShareUrl()
|
||||||
|
isUrlInputVisible = true
|
||||||
|
await tick()
|
||||||
|
// @ts-ignore
|
||||||
|
const height = Math.min(editor['doc'].height * 1.1 + 45, 500)
|
||||||
|
urlInput.value = `<iframe width="100%" height="${height}" frameborder="0" src="${$shareUrl}"></iframe>`
|
||||||
|
urlInput.select()
|
||||||
|
}
|
||||||
|
|
||||||
|
async function copyUrl() {
|
||||||
|
urlInput.select()
|
||||||
|
await navigator.clipboard.writeText(urlInput.value)
|
||||||
|
setTimeout(closeUrlInput, 500)
|
||||||
|
}
|
||||||
|
|
||||||
|
function closeUrlInput() {
|
||||||
|
isUrlInputVisible = false
|
||||||
|
}
|
||||||
|
|
||||||
|
async function goToPreview() {
|
||||||
|
await updateShareUrl()
|
||||||
|
await goto($shareUrl)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div class={cssClass}>
|
||||||
|
{#if isUrlInputVisible}
|
||||||
|
<div class="flex gap-2 grow">
|
||||||
|
<input
|
||||||
|
bind:this={urlInput}
|
||||||
|
type="text"
|
||||||
|
class="border border-gray-300 bg-transparent p-1 grow" />
|
||||||
|
<button class="button" on:click={copyUrl} title="Copy">
|
||||||
|
<Icon class="text-xl" icon="fluent:copy-16-regular" />
|
||||||
|
</button>
|
||||||
|
<button class="button" on:click={closeUrlInput} title="Close">
|
||||||
|
<Icon class="text-xl" icon="material-symbols:close" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<div class="flex justify-end gap-2">
|
||||||
|
<div>
|
||||||
|
<ComboBox
|
||||||
|
items={languages}
|
||||||
|
bind:value={selectedLanguage}
|
||||||
|
class="bg-gray-700 border border-gray-300 p-1" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- Toggle text wrap -->
|
||||||
|
<button class="button" title="Toggle text wrap" on:click={() => (textWrap = !textWrap)}>
|
||||||
|
{#if textWrap}
|
||||||
|
<Icon class="text-xl" icon="fluent:text-wrap-24-filled" />
|
||||||
|
{:else}
|
||||||
|
<Icon class="text-xl" icon="fluent:text-wrap-off-24-filled" />
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- Show link input -->
|
||||||
|
<button class="button" on:click={showUrlInput} title="Get sharing link">
|
||||||
|
<Icon class="text-xl" icon="ph:link-bold" />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- Show markdown link -->
|
||||||
|
<button class="button" on:click={showMarkdownLink} title="Get markdown link">
|
||||||
|
<Icon class="text-xl" icon="simple-icons:markdown" />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- Show HTML iframe -->
|
||||||
|
<button class="button" on:click={showIframeCode} title="Get iframe code">
|
||||||
|
<Icon class="text-xl" icon="fluent:code-24-regular" />
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- Switch to readonly view -->
|
||||||
|
<button class="button" on:click={goToPreview} title="Switch to read-only view">
|
||||||
|
<Icon class="text-xl" icon="fluent:eye-12-regular" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
.button {
|
||||||
|
@apply text-sm border border-gray-300 p-1 hover:bg-gray-600/50;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -1,131 +1,16 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount, tick } from 'svelte'
|
|
||||||
import { shorten } from '$lib/utils'
|
|
||||||
import type { Editor } from 'codemirror'
|
|
||||||
import { shareUrl, selectedLang } from '../store'
|
|
||||||
import ComboBox from './ComboBox.svelte'
|
|
||||||
import Icon from '@iconify/svelte'
|
|
||||||
|
|
||||||
type Language = {
|
|
||||||
text: string
|
|
||||||
value: string
|
|
||||||
data: { mime: string; mode: string }
|
|
||||||
}
|
|
||||||
|
|
||||||
export let editor: Editor | null = null
|
|
||||||
export let updateShareUrl: () => Promise<void>
|
|
||||||
|
|
||||||
let languages: Language[] = []
|
|
||||||
let selectedLanguage: Language | null = null
|
|
||||||
let textWrap = false
|
|
||||||
|
|
||||||
let urlInput: HTMLInputElement
|
|
||||||
let isUrlInputVisible = false
|
|
||||||
|
|
||||||
$: {
|
|
||||||
if (editor) {
|
|
||||||
const language = selectedLanguage?.data ?? { mime: null, mode: null }
|
|
||||||
// @ts-ignore
|
|
||||||
editor.setOption('mode', language.mime)
|
|
||||||
CodeMirror.autoLoadMode(editor, language.mode)
|
|
||||||
$selectedLang = selectedLanguage?.value ?? null
|
|
||||||
|
|
||||||
// Line wrapping
|
|
||||||
editor.setOption('lineWrapping', textWrap)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
onMount(() => {
|
|
||||||
languages = CodeMirror.modeInfo.map((e: any) => ({
|
|
||||||
text: e.name,
|
|
||||||
value: shorten(e.name),
|
|
||||||
data: { mime: e.mime, mode: e.mode },
|
|
||||||
}))
|
|
||||||
})
|
|
||||||
|
|
||||||
export function setLanguage(lang: string) {
|
|
||||||
if (lang === 'mrwn') { // back compatiblity with old links
|
|
||||||
lang = 'md'
|
|
||||||
}
|
|
||||||
const language = languages.find((e) => e.value === lang)!
|
|
||||||
selectedLanguage = language
|
|
||||||
// Automatic text wrap for plain text or markdown
|
|
||||||
if (lang === 'plt' || lang === 'mrwn' || !lang) {
|
|
||||||
textWrap = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function showUrlInput() {
|
|
||||||
// Make sure the url is up to date
|
|
||||||
await updateShareUrl()
|
|
||||||
isUrlInputVisible = true
|
|
||||||
await tick()
|
|
||||||
urlInput.select()
|
|
||||||
}
|
|
||||||
|
|
||||||
async function copyUrl() {
|
|
||||||
urlInput.select()
|
|
||||||
await navigator.clipboard.writeText(urlInput.value)
|
|
||||||
closeUrlInput()
|
|
||||||
}
|
|
||||||
|
|
||||||
function closeUrlInput() {
|
|
||||||
isUrlInputVisible = false
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="flex flex-wrap justify-between items-center px-3 py-1 text-sm relative z-10 shadow-md gap-2"
|
class="flex flex-wrap justify-between items-center px-3 py-1 text-sm w-full z-10 shadow-md gap-2 font-mono bg-gray-700">
|
||||||
>
|
|
||||||
<div class="flex items-center">
|
<div class="flex items-center">
|
||||||
<h1 class="text-xl">Paste</h1>
|
<h1 class="text-xl">
|
||||||
|
<a href="/new" title="Create a new note">Paste</a>
|
||||||
|
</h1>
|
||||||
<span class="ml-8 text-xs">
|
<span class="ml-8 text-xs">
|
||||||
<a
|
<a href="/about" target="_blank">About</a>
|
||||||
href="https://paste.scambier.xyz/?l=mrwn#G14EICwPbMc0BJ69xNPoItLoErDRMwMj3+vxE5RxArxajeByk+b0b1Tm2h/5ugGgK6S83AqUCi09HeYmDs+vvzQc0QDZe7v7U2rHnFe6CTWSm2AArNua4tqtXVIEFVQuqG+is15etOm1OZOPPCH4xDX1iDNF2bQcN9ugum0Icnwj51n0nlvNacn/N3OOctSGrQbLoNzG8n5bSoJQXOx+PsxV+MeUl+rkKNPIAXT9c8LoOY/772FiFkLv/5w8rvtCBc38VEE5lzmGFcZ0QtqlzBhvWLV5WPhRkROqeoKoDCtH03/fQVI5Y8HfLkq2/Nuidd1GQTKgmPJQVWbZ4cAiqUdOJG6j6pvu48qWjqamYG3nFPHcdYLHYCRV877U2mBgSHTbLWv6eu/DEA88SE5XEIqiQFyDVS2HLN7jJSloLHQJ+jOE86zb9jrkQ9tXAwkAoovCcnlrW5T/EU4L7imRsDAkZdEySO/ri/NBuHPMpSFnqGItLlPd98/SZSmySbImOLfv4WGbdCxw9TYykGsk56aQaVSa/DB2t5HfD6x28lJVlMm3Hjnkwyx95PxNGH0teCAk6CqtbBYlC3LjhY0IEpJ0WWZWY6MlJB+jEW7lAN3DSJD0QFz2FZOOV/HwA9LbFBU="
|
|
||||||
target="_blank"
|
|
||||||
>
|
|
||||||
About</a
|
|
||||||
>
|
|
||||||
<a class="ml-4" href="https://git.scambier.xyz/scambier/paste" target="_blank">Source</a>
|
<a class="ml-4" href="https://git.scambier.xyz/scambier/paste" target="_blank">Source</a>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
<slot />
|
||||||
{#if isUrlInputVisible}
|
|
||||||
<div class="flex gap-2 grow">
|
|
||||||
<input
|
|
||||||
bind:this={urlInput}
|
|
||||||
type="text"
|
|
||||||
class="border border-gray-300 bg-transparent p-1 grow"
|
|
||||||
value={$shareUrl}
|
|
||||||
/>
|
|
||||||
<button on:click={copyUrl}>Copy</button>
|
|
||||||
<button on:click={closeUrlInput}>Close</button>
|
|
||||||
</div>
|
|
||||||
{:else}
|
|
||||||
<div class="flex justify-end gap-2">
|
|
||||||
<div>
|
|
||||||
<ComboBox
|
|
||||||
items={languages}
|
|
||||||
bind:value={selectedLanguage}
|
|
||||||
class="bg-gray-700 border border-gray-300 p-1"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<button title="Toggle text wrap" on:click={() => (textWrap = !textWrap)}>
|
|
||||||
{#if textWrap}
|
|
||||||
<Icon class="text-xl" icon="fluent:text-wrap-24-filled" />
|
|
||||||
{:else}
|
|
||||||
<Icon class="text-xl" icon="fluent:text-wrap-off-24-filled" />
|
|
||||||
{/if}
|
|
||||||
</button>
|
|
||||||
<div>
|
|
||||||
<button on:click={showUrlInput}> Generate Link </button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style lang="scss">
|
|
||||||
button {
|
|
||||||
@apply text-sm border border-gray-300 p-1 hover:bg-gray-600/50;
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
Vendored
-6
@@ -1,7 +1 @@
|
|||||||
declare class LZMA {
|
|
||||||
constructor(any): {}
|
|
||||||
compress: (value: string, level: number, callback: (result: number[]) => void) => void
|
|
||||||
decompress: (b: Uint8Array, callback: (result: string, err: any) => void) => void
|
|
||||||
}
|
|
||||||
|
|
||||||
declare const CodeMirror: any
|
declare const CodeMirror: any
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
// LZMA imported from <script> in index.html
|
|
||||||
const blob = new Blob([
|
|
||||||
'importScripts("https://cdn.jsdelivr.net/npm/lzma@2.3.2/src/lzma_worker.min.js");',
|
|
||||||
])
|
|
||||||
const lzma = new LZMA(window.URL.createObjectURL(blob))
|
|
||||||
|
|
||||||
async function compress(value: string): Promise<string> {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
lzma.compress(value, 1, (numbers: number[]) => {
|
|
||||||
const bytes = new Uint8Array(numbers)
|
|
||||||
const b64 = btoa(String.fromCharCode(...bytes))
|
|
||||||
resolve(b64)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function decompress(base64: string): Promise<string> {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
const req = new XMLHttpRequest()
|
|
||||||
req.open('GET', 'data:application/octet;base64,' + base64)
|
|
||||||
req.responseType = 'arraybuffer'
|
|
||||||
req.onload = (e) => {
|
|
||||||
const bytes = new Uint8Array(req.response)
|
|
||||||
lzma.decompress(bytes, (result, err) => {
|
|
||||||
if (err) reject(err)
|
|
||||||
else resolve(result)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
req.send()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export { compress, decompress }
|
|
||||||
+22
-4
@@ -1,3 +1,5 @@
|
|||||||
|
import hljs from 'highlight.js'
|
||||||
|
|
||||||
export const slugify = (str: string) =>
|
export const slugify = (str: string) =>
|
||||||
str
|
str
|
||||||
.trim()
|
.trim()
|
||||||
@@ -10,22 +12,38 @@ export const slugify = (str: string) =>
|
|||||||
|
|
||||||
export const shorten = (name: string) => {
|
export const shorten = (name: string) => {
|
||||||
let n = slugify(name).replace('script', '-s').replace('python', 'py').replace('markdown', 'md')
|
let n = slugify(name).replace('script', '-s').replace('python', 'py').replace('markdown', 'md')
|
||||||
const nov = (s: string) => s[0] + s.substr(1).replace(/[aeiouy-]/g, '')
|
const nov = (s: string) => s[0] + s.substring(1).replace(/[aeiouy-]/g, '')
|
||||||
if (n.replace(/-/g, '').length <= 4) {
|
if (n.replace(/-/g, '').length <= 4) {
|
||||||
return n.replace(/-/g, '')
|
return n.replace(/-/g, '')
|
||||||
}
|
}
|
||||||
if (n.split('-').length >= 2) {
|
if (n.split('-').length >= 2) {
|
||||||
return n
|
return n
|
||||||
.split('-')
|
.split('-')
|
||||||
.map((x) => nov(x.substr(0, 2)))
|
.map((x) => nov(x.substring(0, 2)))
|
||||||
.join('')
|
.join('')
|
||||||
.substr(0, 4)
|
.substring(0, 4)
|
||||||
}
|
}
|
||||||
n = nov(n)
|
n = nov(n)
|
||||||
if (n.length <= 4) {
|
if (n.length <= 4) {
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
return n.substr(0, 2) + n.substr(n.length - 2, 2)
|
return n.substring(0, 2) + n.substring(n.length - 2, 2)
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getLangFromUrl() {
|
||||||
|
return new URLSearchParams(window.location.search).get('l') ?? 'plt'
|
||||||
}
|
}
|
||||||
|
|
||||||
export const byId = (id: string) => document.getElementById(id)
|
export const byId = (id: string) => document.getElementById(id)
|
||||||
|
|
||||||
|
export function isInIframe(): boolean {
|
||||||
|
return window !== window.parent
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getHljsLangFromShort(short: string): string {
|
||||||
|
const langs = hljs
|
||||||
|
.listLanguages()
|
||||||
|
.filter((l) => l !== 'taggerscript') // seriously? This overrides typescript.
|
||||||
|
.map((lang) => ({ lang, short: shorten(lang) }))
|
||||||
|
return langs.find((l) => l.short === short)?.lang ?? 'plaintext'
|
||||||
|
}
|
||||||
@@ -1,2 +1,3 @@
|
|||||||
export const prerender = true
|
export const prerender = true
|
||||||
export const ssr = false
|
export const ssr = false
|
||||||
|
export const trailingSlash = 'always'
|
||||||
+62
-27
@@ -1,72 +1,107 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from 'svelte'
|
import { onMount } from 'svelte'
|
||||||
import * as brotli from '$lib/brotli'
|
|
||||||
import * as lzma from '$lib/lzma'
|
|
||||||
import { unified } from 'unified'
|
import { unified } from 'unified'
|
||||||
import remarkParse from 'remark-parse'
|
import remarkParse from 'remark-parse'
|
||||||
import remarkRehype from 'remark-rehype'
|
import remarkRehype from 'remark-rehype'
|
||||||
|
import remarkGfm from 'remark-gfm'
|
||||||
import rehypeHighlight from 'rehype-highlight'
|
import rehypeHighlight from 'rehype-highlight'
|
||||||
import rehypeStringify from 'rehype-stringify'
|
import rehypeStringify from 'rehype-stringify'
|
||||||
import hljs from 'highlight.js'
|
import hljs from 'highlight.js'
|
||||||
import 'highlight.js/styles/nord.min.css'
|
import 'highlight.js/styles/nord.min.css'
|
||||||
|
import { getHljsLangFromShort, getLangFromUrl, isInIframe } from '$lib/utils'
|
||||||
|
import TopBar from '../components/TopBar.svelte'
|
||||||
|
import Icon from '@iconify/svelte'
|
||||||
|
import CodeView from '../components/CodeView.svelte'
|
||||||
|
import { goto } from '$app/navigation'
|
||||||
|
|
||||||
let decompressed: string
|
let decompressed: string
|
||||||
|
let htmlContent: string
|
||||||
let isMarkdown = false
|
let isMarkdown = false
|
||||||
let isPlainText = false
|
let isPlainText = false
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
let lang = new URLSearchParams(window.location.search).get('l')
|
|
||||||
lang = lang === 'mrwn' ? 'md' : lang // back compatiblity with old links
|
|
||||||
|
|
||||||
// extract the part in the url after the hash
|
// extract the part in the url after the hash
|
||||||
const hash = window.location.hash.slice(1)
|
const hash = window.location.hash.slice(1)
|
||||||
if (hash) {
|
if (hash) {
|
||||||
|
let lang = getLangFromUrl()
|
||||||
|
// Remove github flavored markdown, redundant with markdown
|
||||||
|
lang = lang === 'gflm' ? 'md' : lang
|
||||||
|
|
||||||
|
// Get the correct language name for hljs
|
||||||
|
lang = getHljsLangFromShort(lang)
|
||||||
|
|
||||||
// decompress the data
|
// decompress the data
|
||||||
if (hash.startsWith('XQAAA')) {
|
const { decompress } = await import('$lib/brotli')
|
||||||
decompressed = await lzma.decompress(hash)
|
decompressed = await decompress(hash)
|
||||||
} else {
|
|
||||||
decompressed = await brotli.decompress(hash)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Markdown
|
// Markdown
|
||||||
if (lang === 'md' || lang === 'gflm') {
|
if (lang === 'markdown') {
|
||||||
const html = await unified()
|
const html = await unified()
|
||||||
.use(remarkParse)
|
.use(remarkParse)
|
||||||
|
.use(remarkGfm)
|
||||||
.use(remarkRehype)
|
.use(remarkRehype)
|
||||||
.use(rehypeHighlight)
|
.use(rehypeHighlight)
|
||||||
.use(rehypeStringify)
|
.use(rehypeStringify)
|
||||||
.process(decompressed)
|
.process(decompressed)
|
||||||
isMarkdown = true
|
isMarkdown = true
|
||||||
decompressed = html.toString()
|
htmlContent = html.toString()
|
||||||
}
|
}
|
||||||
// Plain text
|
// Plain text
|
||||||
else if (lang === 'plt' || !lang) {
|
else if (lang === 'plaintext' || !lang) {
|
||||||
isPlainText = true
|
isPlainText = true
|
||||||
}
|
}
|
||||||
// Code
|
// Code
|
||||||
else {
|
else {
|
||||||
decompressed = hljs.highlight(lang, decompressed).value
|
htmlContent = hljs.highlight(decompressed, { language: lang }).value
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Redirect to editor page
|
// Redirect to editor page
|
||||||
window.location.href = '/editor'
|
await goto('/editor')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
function getUrlDataPart(): string {
|
||||||
|
return window.location.search + window.location.hash
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div class="overflow-hidden h-screen flex flex-col">
|
||||||
|
{#if !isInIframe()}
|
||||||
|
<TopBar>
|
||||||
|
<a
|
||||||
|
href={'/editor' + getUrlDataPart()}
|
||||||
|
class="p-1 hover:bg-gray-600/50"
|
||||||
|
title="Edit a copy of this note">
|
||||||
|
<Icon class="text-xl" icon="fluent:document-edit-16-regular" />
|
||||||
|
</a>
|
||||||
|
</TopBar>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<div class="prose dark:prose-invert lg:py-12 p-[0.5em] md:max-w-3xl md:mx-auto lg:max-w-4xl">
|
{#if htmlContent || decompressed}
|
||||||
{#if isMarkdown}
|
<div class="overflow-y-auto grow pb-4">
|
||||||
{@html decompressed}
|
{#if isInIframe()}
|
||||||
{:else if isPlainText}
|
<CodeView
|
||||||
<div class="whitespace-pre-line">
|
class="prose dark:prose-invert w-full max-w-full h-full"
|
||||||
{decompressed}
|
{isMarkdown}
|
||||||
</div>
|
{isPlainText}
|
||||||
{:else}
|
{decompressed}
|
||||||
<pre><code>{@html decompressed}</code></pre>
|
{htmlContent} />
|
||||||
{/if}
|
{:else}
|
||||||
</div>
|
<CodeView
|
||||||
|
class="prose dark:prose-invert lg:py-12 p-[0.5em] md:max-w-3xl md:mx-auto lg:max-w-4xl"
|
||||||
|
{isMarkdown}
|
||||||
|
{isPlainText}
|
||||||
|
{decompressed}
|
||||||
|
{htmlContent} />
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<footer
|
||||||
|
class="absolute bottom-0 left-0 w-full bg-gray-700 px-4 py-1 font-mono text-xs"
|
||||||
|
class:hidden={!isInIframe()}>
|
||||||
|
<a href={window.location.href} target="_blank">Powered by Paste</a>
|
||||||
|
</footer>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { goto } from '$app/navigation'
|
||||||
|
|
||||||
|
goto(
|
||||||
|
'/?l=md#GysKICwPbMcLBD17GY3E2G8DSmoFwEZPDRIY+a4eP0EZJ8Cr1Qgu96X91MeoV4Jrh2wLgNl2heQ+bCycmlBrhRYqvgnDYuNne1vO0j0STTxGIh3Mm7dzpRVJqa7urrpgiUfYC+o8dGHVNxKJkFgsmxK110tv7u4wBMKS9h1GxeLkihii/V9yCyIib9H/WZByLMTCbTooCZTn58WCN8VUWVlKEiXp8UMkCs3aireAUbeJzahqKj8YsACPq+roiSpZbKr/1uuOZWV3SJ7ACiLF83VcZWYk5teMZLP3Eb+qIAHyJklcCeJLMN7dW1qhZ0xX0LTZQr7QBcRi7WgxlLRIicVpJJ5ls4Dee5JlIMgaNP4Z7X1VCpiwzVAUeQ4P5TnJvalhWe/GEcE5m5/W5SPQp8zhcU3DgKOvTD1RViuRxWakddH4v4R3AUdIi5Ov+vH1K2Lwvz4ECp5bCagC46ldwAI7T/vXdMUSBBJvq6K79b1OaYmIyzTrpdXPjZ3VTmVow4xrUj7W1V/nVvzybSGFP/PdoZ6HE5J3UprPpfEMKSNyZwmWz0RkRfE37lkPKrQfAdaARtsj8Oa+fohb+VSm+7oWQPHNSWp9w7OyewEqz0uIMYbMBLjmcxelEBzqVQ0RxZ4EN4IuPoCeXc2IUeROMJA2xSqlZVz4g+LRoXX99bwZfEm4+LQrIBO0OgFPpoFYN7YulcYvcT6HoWXfpW6B0n2OsC1c+hrubOXPuNlcmjUdlYeVx4xfrPxd6TTLAaUzXSPbbr3zoy0uDQkxVgJrUB8OZqWbebFZe1uie3up259eURT0mOyNWEzlvEIuhF9hoEVQByqiHCaG6TGESuutg+pRUEBbHss2OG/+VVUqk7OFc0H6E+tfCQrkF4/O4ZJ9QGmvh1+skE7Msns6TAmP+JmoBR52K4uAN+YkRtvC9xq9EoYUAiQ+n64Cs6fJ67UNAaU89DBZFxh2yEz9uye5uMAh26qErePAJNigv/9+f22Pe7DBbGvZRIFZV2i/Use/IBuRqkZs3CSw3FywVBvNUU5Sf/moD6N3/cmGuy/A/FonF4csOS5ctRQ70WerDvqKdq080+cCI4BpNvK4aX7f8mV7HI+afPdQIV+ifUwBLA=='
|
||||||
|
)
|
||||||
|
</script>
|
||||||
@@ -1,13 +1,11 @@
|
|||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { Editor } from 'codemirror'
|
import type { Editor } from 'codemirror'
|
||||||
import { onMount } from 'svelte'
|
|
||||||
import { debounce } from 'lodash-es'
|
import { debounce } from 'lodash-es'
|
||||||
import * as brotli from '$lib/brotli'
|
import * as brotli from '$lib/brotli'
|
||||||
import * as lzma from '$lib/lzma'
|
|
||||||
import { byId } from '$lib/utils'
|
import { byId } from '$lib/utils'
|
||||||
import TopBar from '../../components/TopBar.svelte'
|
import TopBar from '../../components/TopBar.svelte'
|
||||||
import { selectedLang, shareUrl } from '../../store'
|
import { selectedLang, shareUrl } from '../../store'
|
||||||
|
import EditForm from '../../components/EditForm.svelte'
|
||||||
|
|
||||||
let editor: Editor | null = null
|
let editor: Editor | null = null
|
||||||
const readOnly = false
|
const readOnly = false
|
||||||
@@ -15,39 +13,13 @@
|
|||||||
let charLen = 0
|
let charLen = 0
|
||||||
let compressed: string = ''
|
let compressed: string = ''
|
||||||
let waiting = false
|
let waiting = false
|
||||||
let setLanguage: (lang: string) => void
|
|
||||||
|
|
||||||
onMount(async () => {
|
|
||||||
initCodeEditor()
|
|
||||||
// extract the part in the url after the hash
|
|
||||||
const hash = window.location.hash.slice(1)
|
|
||||||
if (hash) {
|
|
||||||
// decompress the data
|
|
||||||
let decompressed: string
|
|
||||||
if (hash.startsWith('XQAAA')) {
|
|
||||||
decompressed = await lzma.decompress(hash)
|
|
||||||
} else {
|
|
||||||
decompressed = await brotli.decompress(hash)
|
|
||||||
}
|
|
||||||
// set the editor value
|
|
||||||
if (editor) {
|
|
||||||
editor.setValue(decompressed)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const lang = new URLSearchParams(window.location.search).get('l')
|
|
||||||
if (lang) {
|
|
||||||
setLanguage(lang)
|
|
||||||
} else {
|
|
||||||
setLanguage('plt')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
async function updateShareUrl() {
|
async function updateShareUrl() {
|
||||||
if (editor) {
|
if (editor) {
|
||||||
const url = new URL(window.location.origin)
|
const url = new URL(window.location.origin)
|
||||||
compressed = await brotli.compress(editor.getValue())
|
compressed = await brotli.compress(editor.getValue())
|
||||||
if ($selectedLang) {
|
// Set the language (ignore for plain text, since it's the default)
|
||||||
|
if ($selectedLang && $selectedLang !== 'plt') {
|
||||||
url.searchParams.set('l', $selectedLang)
|
url.searchParams.set('l', $selectedLang)
|
||||||
}
|
}
|
||||||
url.hash = compressed
|
url.hash = compressed
|
||||||
@@ -60,7 +32,9 @@
|
|||||||
waiting = false
|
waiting = false
|
||||||
}, 1000)
|
}, 1000)
|
||||||
|
|
||||||
const initCodeEditor = () => {
|
async function initCodeEditor() {
|
||||||
|
$selectedLang = new URLSearchParams(window.location.search).get('l') ?? 'plt'
|
||||||
|
|
||||||
CodeMirror.modeURL = 'https://cdn.jsdelivr.net/npm/codemirror@5.65.16/mode/%N/%N.js'
|
CodeMirror.modeURL = 'https://cdn.jsdelivr.net/npm/codemirror@5.65.16/mode/%N/%N.js'
|
||||||
editor = new CodeMirror(byId('editor'), {
|
editor = new CodeMirror(byId('editor'), {
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
@@ -81,11 +55,43 @@
|
|||||||
updateShareUrlDebounced()
|
updateShareUrlDebounced()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// extract the part in the url after the hash
|
||||||
|
const hash = window.location.hash.slice(1)
|
||||||
|
if (hash) {
|
||||||
|
// decompress the data
|
||||||
|
const decompressed = await brotli.decompress(hash)
|
||||||
|
// set the editor value
|
||||||
|
if (editor) {
|
||||||
|
editor.setValue(decompressed)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<svelte:head>
|
||||||
|
<script
|
||||||
|
src="https://cdn.jsdelivr.net/combine/
|
||||||
|
npm/codemirror@5.65.16,
|
||||||
|
npm/codemirror@5.65.16/addon/mode/loadmode.min.js,
|
||||||
|
npm/codemirror@5.65.16/addon/mode/overlay.min.js,
|
||||||
|
npm/codemirror@5.65.16/addon/mode/multiplex.min.js,
|
||||||
|
npm/codemirror@5.65.16/addon/mode/simple.min.js,
|
||||||
|
npm/codemirror@5.65.16/addon/scroll/simplescrollbars.js,
|
||||||
|
npm/codemirror@5.65.16/mode/meta.min.js"
|
||||||
|
on:load={initCodeEditor}></script>
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
type="text/css"
|
||||||
|
href="https://cdn.jsdelivr.net/combine/
|
||||||
|
npm/codemirror@5.65.16/lib/codemirror.min.css,
|
||||||
|
npm/codemirror@5.65.16/theme/nord.min.css" />
|
||||||
|
</svelte:head>
|
||||||
|
|
||||||
<div class="flex flex-col font-mono h-screen bg-gray-700">
|
<div class="flex flex-col font-mono h-screen bg-gray-700">
|
||||||
<TopBar {editor} {updateShareUrl} bind:setLanguage />
|
<TopBar>
|
||||||
|
<EditForm {editor} {updateShareUrl} class="grow" />
|
||||||
|
</TopBar>
|
||||||
|
|
||||||
<div id="editor" class="grow overflow-hidden" />
|
<div id="editor" class="grow overflow-hidden" />
|
||||||
|
|
||||||
@@ -98,13 +104,13 @@
|
|||||||
? '?'
|
? '?'
|
||||||
: Math.round(($shareUrl.length / charLen) * 100)}% of original)
|
: Math.round(($shareUrl.length / charLen) * 100)}% of original)
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
:global(div.CodeMirror) {
|
:global(div.CodeMirror) {
|
||||||
height: 100%;
|
height: 100%;
|
||||||
font-size: 15px;
|
font-size: 14px;
|
||||||
|
font-family: 'Hack', monospace;
|
||||||
}
|
}
|
||||||
#footer {
|
#footer {
|
||||||
--tw-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
|
--tw-shadow: 0 -4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { goto } from '$app/navigation'
|
||||||
|
|
||||||
|
goto('/editor')
|
||||||
|
</script>
|
||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
import { writable } from 'svelte/store'
|
import { writable } from 'svelte/store'
|
||||||
|
|
||||||
export const shareUrl = writable('')
|
export const shareUrl = writable('')
|
||||||
export const selectedLang = writable<string | null>(null)
|
export const selectedLang = writable<string>('plt')
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 4.2 KiB |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="1em" height="1em" viewBox="0 0 32 32"><g fill="none"><path fill="#E19747" d="M5 4.5A1.5 1.5 0 0 1 6.5 3h19A1.5 1.5 0 0 1 27 4.5v24a1.5 1.5 0 0 1-1.5 1.5h-19A1.5 1.5 0 0 1 5 28.5v-24Z"/><path fill="#F3EEF8" d="M25 6a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v21a1 1 0 0 0 1 1h10.586c.147 0 .29-.032.421-.093l.321-.783l.632-4.086l4.457-.783l.49-.247a1 1 0 0 0 .093-.422V6Z"/><path fill="#CDC4D6" d="M24.91 22H20a1 1 0 0 0-1 1v4.91a1 1 0 0 0 .293-.203l5.414-5.414A1 1 0 0 0 24.91 22Z"/><path fill="#9B9B9B" d="M18 4a2 2 0 1 0-4 0h-1a2 2 0 0 0-2 2v1.5a.5.5 0 0 0 .5.5h9a.5.5 0 0 0 .5-.5V6a2 2 0 0 0-2-2h-1Zm-1 0a1 1 0 1 1-2 0a1 1 0 0 1 2 0Zm-8 8.5a.5.5 0 0 1 .5-.5h13a.5.5 0 0 1 0 1h-13a.5.5 0 0 1-.5-.5Zm0 3a.5.5 0 0 1 .5-.5h13a.5.5 0 0 1 0 1h-13a.5.5 0 0 1-.5-.5Zm.5 2.5a.5.5 0 0 0 0 1h13a.5.5 0 0 0 0-1h-13ZM9 21.5a.5.5 0 0 1 .5-.5h8a.5.5 0 0 1 0 1h-8a.5.5 0 0 1-.5-.5Z"/></g></svg>
|
||||||
|
After Width: | Height: | Size: 915 B |
@@ -1,116 +0,0 @@
|
|||||||
/* 0. extract fonts into `JetBrainsMono` folder */
|
|
||||||
/* 1. check fonts `urls` with your directory structure */
|
|
||||||
|
|
||||||
/* normal fonts */
|
|
||||||
|
|
||||||
@font-face {
|
|
||||||
font-family: JetBrainsMono;
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 100;
|
|
||||||
src: url("/fonts/JetBrainsMono-Thin.woff2") format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: JetBrainsMono;
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 200;
|
|
||||||
src: url("/fonts/JetBrainsMono-ExtraLight.woff2")
|
|
||||||
format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: JetBrainsMono;
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 300;
|
|
||||||
src: url("/fonts/JetBrainsMono-Light.woff2") format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: JetBrainsMono;
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 400;
|
|
||||||
src: url("/fonts/JetBrainsMono-Regular.woff2") format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: JetBrainsMono;
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 500;
|
|
||||||
src: url("/fonts/JetBrainsMono-Medium.woff2") format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: JetBrainsMono;
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 600;
|
|
||||||
src: url("/fonts/JetBrainsMono-SemiBold.woff2") format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: JetBrainsMono;
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 700;
|
|
||||||
src: url("/fonts/JetBrainsMono-Bold.woff2") format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: JetBrainsMono;
|
|
||||||
font-style: normal;
|
|
||||||
font-weight: 800;
|
|
||||||
src: url("/fonts/JetBrainsMono-ExtraBold.woff2")
|
|
||||||
format("woff2");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* italic fonts */
|
|
||||||
|
|
||||||
@font-face {
|
|
||||||
font-family: JetBrainsMono;
|
|
||||||
font-style: italic;
|
|
||||||
font-weight: 100;
|
|
||||||
src: url("/fonts/JetBrainsMono-ThinItalic.woff2")
|
|
||||||
format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: JetBrainsMono;
|
|
||||||
font-style: italic;
|
|
||||||
font-weight: 200;
|
|
||||||
format("truetype");
|
|
||||||
src: url("/fonts/JetBrainsMono-ExtraLightItalic.woff2")
|
|
||||||
format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: JetBrainsMono;
|
|
||||||
font-style: italic;
|
|
||||||
font-weight: 300;
|
|
||||||
src: url("/fonts/JetBrainsMono-LightItalic.woff2")
|
|
||||||
format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: JetBrainsMono;
|
|
||||||
font-style: italic;
|
|
||||||
font-weight: 400;
|
|
||||||
src: url("/fonts/JetBrainsMono-Italic.woff2") format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: JetBrainsMono;
|
|
||||||
font-style: italic;
|
|
||||||
font-weight: 500;
|
|
||||||
src: url("/fonts/JetBrainsMono-MediumItalic.woff2")
|
|
||||||
format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: JetBrainsMono;
|
|
||||||
font-style: italic;
|
|
||||||
font-weight: 600;
|
|
||||||
format("truetype");
|
|
||||||
src: url("/fonts/JetBrainsMono-SemiBoldItalic.woff2")
|
|
||||||
format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: JetBrainsMono;
|
|
||||||
font-style: italic;
|
|
||||||
font-weight: 700;
|
|
||||||
src: url("/fonts/JetBrainsMono-BoldItalic.woff2")
|
|
||||||
format("woff2");
|
|
||||||
}
|
|
||||||
@font-face {
|
|
||||||
font-family: JetBrainsMono;
|
|
||||||
font-style: italic;
|
|
||||||
font-weight: 800;
|
|
||||||
format("truetype");
|
|
||||||
src: url("/fonts/JetBrainsMono-ExtraBoldItalic.woff2")
|
|
||||||
format("woff2");
|
|
||||||
}
|
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,34 @@
|
|||||||
|
/*!
|
||||||
|
* Hack typeface https://github.com/source-foundry/Hack
|
||||||
|
* License: https://github.com/source-foundry/Hack/blob/master/LICENSE.md
|
||||||
|
*/
|
||||||
|
/* FONT PATHS
|
||||||
|
* -------------------------- */
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Hack';
|
||||||
|
src: url('fonts/hack-regular-subset.woff2?sha=3114f1256') format('woff2'), url('fonts/hack-regular-subset.woff?sha=3114f1256') format('woff');
|
||||||
|
font-weight: 400;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Hack';
|
||||||
|
src: url('fonts/hack-bold-subset.woff2?sha=3114f1256') format('woff2'), url('fonts/hack-bold-subset.woff?sha=3114f1256') format('woff');
|
||||||
|
font-weight: 700;
|
||||||
|
font-style: normal;
|
||||||
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Hack';
|
||||||
|
src: url('fonts/hack-italic-subset.woff2?sha=3114f1256') format('woff2'), url('fonts/hack-italic-webfont.woff?sha=3114f1256') format('woff');
|
||||||
|
font-weight: 400;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
|
@font-face {
|
||||||
|
font-family: 'Hack';
|
||||||
|
src: url('fonts/hack-bolditalic-subset.woff2?sha=3114f1256') format('woff2'), url('fonts/hack-bolditalic-subset.woff?sha=3114f1256') format('woff');
|
||||||
|
font-weight: 700;
|
||||||
|
font-style: italic;
|
||||||
|
}
|
||||||
|
|
||||||
+1
-1
@@ -6,7 +6,7 @@ export default {
|
|||||||
theme: {
|
theme: {
|
||||||
extend: {
|
extend: {
|
||||||
fontFamily: {
|
fontFamily: {
|
||||||
mono: ['"JetBrainsMono"', ...defaultTheme.fontFamily.mono],
|
mono: ['"Hack"', ...defaultTheme.fontFamily.mono],
|
||||||
},
|
},
|
||||||
typography: {
|
typography: {
|
||||||
DEFAULT: {
|
DEFAULT: {
|
||||||
|
|||||||
+16
-16
@@ -1,17 +1,17 @@
|
|||||||
{
|
{
|
||||||
"extends": "./.svelte-kit/tsconfig.json",
|
"extends": "./.svelte-kit/tsconfig.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"checkJs": true,
|
"checkJs": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"forceConsistentCasingInFileNames": true,
|
"forceConsistentCasingInFileNames": true,
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"skipLibCheck": true,
|
"skipLibCheck": true,
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"strict": true
|
"strict": true
|
||||||
}
|
}
|
||||||
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
|
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
|
||||||
//
|
//
|
||||||
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
|
// If you want to overwrite includes/excludes, make sure to copy over the relevant includes/excludes
|
||||||
// from the referenced tsconfig.json - TypeScript does not merge them in
|
// from the referenced tsconfig.json - TypeScript does not merge them in
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user