wavesurfer.js 7.0.0-alpha.0 → 7.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/renderer.ts DELETED
@@ -1,250 +0,0 @@
1
- import EventEmitter from './event-emitter.js'
2
-
3
- type RendererOptions = {
4
- container: HTMLElement | string | null
5
- height: number
6
- waveColor: string
7
- progressColor: string
8
- minPxPerSec: number
9
- barWidth?: number
10
- barGap?: number
11
- barRadius?: number
12
- }
13
-
14
- type RendererEvents = {
15
- click: { relativeX: number }
16
- }
17
-
18
- class Renderer extends EventEmitter<RendererEvents> {
19
- private options: RendererOptions
20
- private container: HTMLElement
21
- private shadowRoot: ShadowRoot
22
- private mainCanvas: HTMLCanvasElement
23
- private progressCanvas: HTMLCanvasElement
24
- private cursor: HTMLElement
25
- private ctx: CanvasRenderingContext2D
26
-
27
- constructor(options: RendererOptions) {
28
- super()
29
-
30
- this.options = options
31
-
32
- let container: HTMLElement | null = null
33
- if (typeof this.options.container === 'string') {
34
- container = document.querySelector(this.options.container)
35
- } else if (this.options.container instanceof HTMLElement) {
36
- container = this.options.container
37
- }
38
- if (!container) {
39
- throw new Error('Container not found')
40
- }
41
-
42
- const div = document.createElement('div')
43
- const shadow = div.attachShadow({ mode: 'open' })
44
-
45
- shadow.innerHTML = `
46
- <style>
47
- :host .scroll {
48
- overflow-x: auto;
49
- overflow-y: visible;
50
- user-select: none;
51
- width: 100%;
52
- height: ${this.options.height}px;
53
- position: relative;
54
- }
55
- :host .wrapper {
56
- position: relative;
57
- width: fit-content;
58
- min-width: 100%;
59
- height: 100%;
60
- z-index: 2;
61
- }
62
- :host canvas {
63
- display: block;
64
- height: 100%;
65
- min-width: 100%;
66
- image-rendering: pixelated;
67
- }
68
- :host .progress {
69
- position: absolute;
70
- z-index: 2;
71
- top: 0;
72
- left: 0;
73
- height: 100%;
74
- pointer-events: none;
75
- clip-path: inset(100%);
76
- }
77
- :host .cursor {
78
- position: absolute;
79
- z-index: 3;
80
- top: 0;
81
- left: 0;
82
- height: 100%;
83
- border-right: 1px solid ${this.options.progressColor};
84
- }
85
- </style>
86
-
87
- <div class="scroll">
88
- <div class="wrapper">
89
- <canvas></canvas>
90
- <canvas class="progress"></canvas>
91
- <div class="cursor"></div>
92
- </div>
93
- </div>
94
- `
95
-
96
- this.container = div
97
- this.shadowRoot = shadow
98
- this.mainCanvas = shadow.querySelector('canvas') as HTMLCanvasElement
99
- this.ctx = this.mainCanvas.getContext('2d', { desynchronized: true }) as CanvasRenderingContext2D
100
- this.progressCanvas = shadow.querySelector('.progress') as HTMLCanvasElement
101
- this.cursor = shadow.querySelector('.cursor') as HTMLElement
102
- container.appendChild(div)
103
-
104
- this.mainCanvas.addEventListener('click', (e) => {
105
- const rect = this.mainCanvas.getBoundingClientRect()
106
- const x = e.clientX - rect.left
107
- const relativeX = x / rect.width
108
- this.emit('click', { relativeX })
109
- })
110
- }
111
-
112
- destroy() {
113
- this.container.remove()
114
- }
115
-
116
- private renderLinePeaks(channelData: Float32Array[], width: number, height: number) {
117
- const { ctx } = this
118
- ctx.clearRect(0, 0, width, height)
119
- ctx.beginPath()
120
- ctx.moveTo(0, height / 2)
121
-
122
- // Channel 0 is left, 1 is right
123
- const leftChannel = channelData[0]
124
- const isMono = channelData.length === 1
125
- const rightChannel = isMono ? leftChannel : channelData[1]
126
-
127
- // Draw left channel in the top half of the canvas
128
- let prevX = -1
129
- let prevY = 0
130
- for (let i = 0, len = leftChannel.length; i < len; i++) {
131
- const x = Math.round((i / leftChannel.length) * width)
132
- const y = Math.round(((1 - leftChannel[i]) * height) / 2)
133
- if (x !== prevX || y > prevY) {
134
- ctx.lineTo(x, y)
135
- prevX = x
136
- prevY = y
137
- }
138
- }
139
-
140
- // Draw right channel in the bottom half of the canvas
141
- prevX = -1
142
- prevY = 0
143
- for (let i = rightChannel.length - 1; i >= 0; i--) {
144
- const x = Math.round((i / rightChannel.length) * width)
145
- const y = Math.round(((1 + rightChannel[i]) * height) / 2)
146
- if (x !== prevX || (isMono ? y < -prevY : y > prevY)) {
147
- ctx.lineTo(x, y)
148
- prevX = x
149
- prevY = y
150
- }
151
- }
152
-
153
- ctx.strokeStyle = ctx.fillStyle = this.options.waveColor
154
- ctx.stroke()
155
- ctx.fill()
156
- }
157
-
158
- private renderBarPeaks(channelData: Float32Array[], width: number, height: number) {
159
- const { devicePixelRatio } = window
160
- const { ctx } = this
161
- ctx.clearRect(0, 0, width, height)
162
-
163
- const barWidthOption = this.options.barWidth || 1
164
- const barWidth = barWidthOption * devicePixelRatio
165
- const barGap = (this.options.barGap ?? barWidthOption / 2) * devicePixelRatio
166
- const barRadius = this.options.barRadius ?? 0
167
-
168
- const leftChannel = channelData[0]
169
- const isMono = channelData.length === 1
170
- const rightChannel = isMono ? leftChannel : channelData[1]
171
-
172
- const barCount = Math.floor(width / (barWidth + barGap))
173
-
174
- const leftChannelBars = new Float32Array(barCount)
175
- const rightChannelBars = new Float32Array(barCount)
176
-
177
- const barIndexScale = barCount / leftChannel.length
178
- const leftChannelLength = leftChannel.length
179
- for (let i = 0; i < leftChannelLength; i++) {
180
- const barIndex = Math.round(i * barIndexScale)
181
- leftChannelBars[barIndex] = Math.max(leftChannelBars[barIndex], leftChannel[i])
182
- rightChannelBars[barIndex] = (isMono ? Math.min : Math.max)(rightChannelBars[barIndex], rightChannel[i])
183
- }
184
-
185
- ctx.beginPath()
186
-
187
- for (let i = 0; i < barCount; i++) {
188
- const leftBarHeight = Math.max(1, Math.round((leftChannelBars[i] * height) / 2))
189
- const rightBarHeight = Math.max(1, Math.round(Math.abs(rightChannelBars[i] * height) / 2))
190
-
191
- ctx.roundRect(
192
- i * (barWidth + barGap),
193
- height / 2 - leftBarHeight,
194
- barWidth,
195
- leftBarHeight + rightBarHeight,
196
- barRadius,
197
- )
198
- }
199
-
200
- ctx.fillStyle = this.options.waveColor
201
- ctx.fill()
202
- }
203
-
204
- render(channelData: Float32Array[], duration: number, minPxPerSec = this.options.minPxPerSec) {
205
- const { devicePixelRatio } = window
206
- const width = Math.max(this.container.clientWidth * devicePixelRatio, duration * minPxPerSec)
207
- const { height } = this.options
208
- this.mainCanvas.width = width
209
- this.mainCanvas.height = height
210
- this.mainCanvas.style.width = Math.round(width / devicePixelRatio) + 'px'
211
-
212
- const renderingFn = this.options.barWidth ? this.renderBarPeaks : this.renderLinePeaks
213
- renderingFn.call(this, channelData, width, height)
214
- this.createProgressMask()
215
- }
216
-
217
- private createProgressMask() {
218
- const progressCtx = this.progressCanvas.getContext('2d', { desynchronized: true })
219
- if (!progressCtx) {
220
- throw new Error('Failed to get canvas context')
221
- }
222
- this.progressCanvas.width = this.mainCanvas.width
223
- this.progressCanvas.height = this.mainCanvas.height
224
- this.progressCanvas.style.width = this.mainCanvas.style.width
225
- this.progressCanvas.style.height = this.mainCanvas.style.height
226
- progressCtx.drawImage(this.mainCanvas, 0, 0)
227
- progressCtx.globalCompositeOperation = 'source-in'
228
- progressCtx.fillStyle = this.options.progressColor
229
- progressCtx.fillRect(0, 0, this.progressCanvas.width, this.progressCanvas.height)
230
- }
231
-
232
- renderProgress(progress: number, autoCenter = false) {
233
- this.progressCanvas.style.clipPath = `inset(0 ${100 - progress * 100}% 0 0)`
234
- this.cursor.style.left = `${progress * 100}%`
235
-
236
- if (autoCenter) {
237
- const center = this.container.clientWidth / 2
238
- const fullWidth = this.mainCanvas.clientWidth
239
- if (fullWidth * progress >= center) {
240
- this.container.scrollLeft = fullWidth * progress - center
241
- }
242
- }
243
- }
244
-
245
- getContainer(): HTMLElement {
246
- return this.shadowRoot.querySelector('.scroll') as HTMLElement
247
- }
248
- }
249
-
250
- export default Renderer
package/src/timer.ts DELETED
@@ -1,27 +0,0 @@
1
- import EventEmitter from './event-emitter.js'
2
-
3
- type TimerEvents = {
4
- tick: void
5
- }
6
-
7
- class Timer extends EventEmitter<TimerEvents> {
8
- private unsubscribe: () => void = () => undefined
9
-
10
- constructor() {
11
- super()
12
-
13
- this.unsubscribe = this.on('tick', () => {
14
- requestAnimationFrame(() => {
15
- this.emit('tick')
16
- })
17
- })
18
-
19
- this.emit('tick')
20
- }
21
-
22
- destroy() {
23
- this.unsubscribe()
24
- }
25
- }
26
-
27
- export default Timer
package/tsconfig.json DELETED
@@ -1,105 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- /* Visit https://aka.ms/tsconfig.json to read more about this file */
4
-
5
- /* Projects */
6
- // "incremental": true, /* Enable incremental compilation */
7
- // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
8
- // "tsBuildInfoFile": "./", /* Specify the folder for .tsbuildinfo incremental compilation files. */
9
- // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects */
10
- // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
11
- // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
12
-
13
- /* Language and Environment */
14
- "target": "es2016", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
15
- "lib": [ "es2019", "dom" ],
16
- // "jsx": "preserve", /* Specify what JSX code is generated. */
17
- // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */
18
- // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
19
- // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h' */
20
- // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
21
- // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using `jsx: react-jsx*`.` */
22
- // "reactNamespace": "", /* Specify the object invoked for `createElement`. This only applies when targeting `react` JSX emit. */
23
- // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
24
- // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
25
-
26
- /* Modules */
27
- "module": "esnext",
28
- // "rootDir": "./", /* Specify the root folder within your source files. */
29
- // "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */
30
- // "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */
31
- // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
32
- // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
33
- // "typeRoots": [], /* Specify multiple folders that act like `./node_modules/@types`. */
34
- // "types": [], /* Specify type package names to be included without being referenced in a source file. */
35
- // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
36
- // "resolveJsonModule": true, /* Enable importing .json files */
37
- // "noResolve": true, /* Disallow `import`s, `require`s or `<reference>`s from expanding the number of files TypeScript should add to a project. */
38
-
39
- /* JavaScript Support */
40
- // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the `checkJS` option to get errors from these files. */
41
- // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
42
- // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from `node_modules`. Only applicable with `allowJs`. */
43
-
44
- /* Emit */
45
- "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
46
- // "declarationMap": true, /* Create sourcemaps for d.ts files. */
47
- // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
48
- // "sourceMap": true, /* Create source map files for emitted JavaScript files. */
49
- // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If `declaration` is true, also designates a file that bundles all .d.ts output. */
50
- "outDir": "./dist", /* Specify an output folder for all emitted files. */
51
- // "removeComments": true, /* Disable emitting comments. */
52
- // "noEmit": true, /* Disable emitting files from a compilation. */
53
- // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
54
- // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types */
55
- // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
56
- // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
57
- // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
58
- // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
59
- // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
60
- // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
61
- // "newLine": "crlf", /* Set the newline character for emitting files. */
62
- // "stripInternal": true, /* Disable emitting declarations that have `@internal` in their JSDoc comments. */
63
- // "noEmitHelpers": true, /* Disable generating custom helper functions like `__extends` in compiled output. */
64
- // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
65
- // "preserveConstEnums": true, /* Disable erasing `const enum` declarations in generated code. */
66
- // "declarationDir": "./", /* Specify the output directory for generated declaration files. */
67
- // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
68
-
69
- /* Interop Constraints */
70
- // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */
71
- // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
72
- "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables `allowSyntheticDefaultImports` for type compatibility. */
73
- // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
74
- "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
75
-
76
- /* Type Checking */
77
- "strict": true, /* Enable all strict type-checking options. */
78
- // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied `any` type.. */
79
- // "strictNullChecks": true, /* When type checking, take into account `null` and `undefined`. */
80
- // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
81
- // "strictBindCallApply": true, /* Check that the arguments for `bind`, `call`, and `apply` methods match the original function. */
82
- // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
83
- // "noImplicitThis": true, /* Enable error reporting when `this` is given the type `any`. */
84
- // "useUnknownInCatchVariables": true, /* Type catch clause variables as 'unknown' instead of 'any'. */
85
- // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
86
- // "noUnusedLocals": true, /* Enable error reporting when a local variables aren't read. */
87
- // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read */
88
- // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
89
- // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
90
- // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */
91
- // "noUncheckedIndexedAccess": true, /* Include 'undefined' in index signature results */
92
- // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
93
- // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type */
94
- // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
95
- // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
96
-
97
- /* Completeness */
98
- // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
99
- "skipLibCheck": true /* Skip type checking all .d.ts files. */
100
- },
101
- "exclude": [
102
- "node_modules",
103
- "dist"
104
- ]
105
- }
@@ -1,47 +0,0 @@
1
- <html>
2
- <head>
3
- <meta charset="utf-8" />
4
-
5
- <title>wavesurfer.ts examples</title>
6
-
7
- <link rel="stylesheet" href="style.css" />
8
-
9
- <script src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.32.0-dev.20211218/min/vs/loader.min.js" integrity="sha512-O9SYDgWAM3bEzit1z6mkFd+dxKUplO/oB8UwYGAkg2Zy/WzDUQ2mYA/ysk3c0CxiXAN4u8T9JeZ0Ahk2Jj/33Q==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
10
- </head>
11
-
12
- <body>
13
- <div class="layout">
14
- <header>
15
- <h1>wavesurfer.ts examples</h1>
16
-
17
- <a href="/docs">Documentation</a>
18
- </header>
19
-
20
- <div class="grid">
21
- <div class="sidebar">
22
- <ul>
23
- <li><a href="/examples/basic.js">Basic</a></li>
24
- <li><a href="/examples/regions.js">Regions</a></li>
25
- <li><a href="/examples/video.js">Video</a></li>
26
- <li><a href="/examples/bars.js">Bars</a></li>
27
- <li><a href="/examples/gradient.js">Gradient</a></li>
28
- <li><a href="/examples/webaudio.js">Web Audio</a></li>
29
- </ul>
30
- </div>
31
-
32
- <div id="editor"></div>
33
-
34
- <div class="preview">
35
- <iframe id="preview" sandbox="allow-scripts allow-same-origin"></iframe>
36
- </div>
37
- </div>
38
-
39
- <footer>
40
- <a class="github" href="https://github.com/katspaugh/wavesurfer.ts">katspaugh/wavesurfer.ts</a>
41
- This app was built using the <a href="https://microsoft.github.io/monaco-editor/">Monaco editor</a>
42
- </footer>
43
- </div>
44
-
45
- <script type="module" src="src/init.js"></script>
46
- </body>
47
- </html>
@@ -1,70 +0,0 @@
1
- let editor = null
2
-
3
- export const getContent = () => {
4
- return editor ? editor.getModel().getValue() : ''
5
- }
6
-
7
- export const setContent = (newContent) => {
8
- if (!editor) {
9
- setTimeout(() => setContent(newContent), 10)
10
- } else {
11
- editor.getModel().setValue(newContent)
12
- }
13
- }
14
-
15
- const fetchCode = async (url) => {
16
- return fetch(url).then((res) => res.text())
17
- }
18
-
19
- export const initEditor = (onSetContent) => {
20
- require.config({ paths: { vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.32.0-dev.20211218/min/vs' } });
21
-
22
- require(['vs/editor/editor.main'], () => {
23
- let theme = 'vs'
24
- if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
25
- theme = 'vs-dark'
26
- }
27
-
28
- monaco.languages.typescript.typescriptDefaults.setCompilerOptions({
29
- lib: [ 'es2019', 'dom' ],
30
- allowJs: true,
31
- allowNonTsExtensions: true,
32
- baseUrl: window.location.origin,
33
- moduleResolution: monaco.languages.typescript.ModuleResolutionKind.Classic,
34
- })
35
-
36
- const libs = [
37
- '/dist/index.d.ts',
38
- '/dist/event-emitter.d.ts',
39
- '/dist/plugins/regions.d.ts',
40
- ]
41
-
42
- Promise.all(
43
- libs.map(url => fetchCode(url))
44
- ).then((codes) => {
45
- codes.forEach((code, index) => {
46
- monaco.languages.typescript.typescriptDefaults.addExtraLib(code, libs[index])
47
- })
48
- }).then(() => {
49
- const monacoEditor = monaco.editor.create(document.getElementById('editor'), {
50
- language: 'typescript',
51
- quickSuggestions: true,
52
- automaticLayout: true,
53
- autoClosingBrackets: false,
54
- minimap: { enabled: false },
55
- tabSize: 2,
56
- theme
57
- });
58
-
59
- let debounce
60
- const model = monacoEditor.getModel()
61
- model.onDidChangeContent(() => {
62
- if (debounce) clearTimeout(debounce)
63
- debounce = setTimeout(onSetContent, 300)
64
- })
65
-
66
- // Export
67
- editor = monacoEditor
68
- })
69
- })
70
- }
@@ -1,66 +0,0 @@
1
- import { initEditor, setContent, getContent } from './editor.js'
2
-
3
- const onSetContent = () => {
4
- const code = getContent()
5
- document.getElementById('preview').srcdoc = `
6
- <!DOCTYPE html>
7
- <html>
8
- <head>
9
- <meta charset="utf-8">
10
- <title>Preview</title>
11
- <style>
12
- html, body {
13
- background-color: transparent;
14
- margin: 0;
15
- padding: 0;
16
- }
17
- body {
18
- padding: 1rem;
19
- }
20
- </style>
21
- </head>
22
- <body>
23
- <script type="module">
24
- ${code}
25
- </script>
26
- </body>
27
- </html>
28
- <body>
29
- </body>
30
- `
31
- }
32
-
33
- const fetchContent = async (url) => {
34
- return fetch(url).then(res => res.text())
35
- }
36
-
37
- const init = () => {
38
- let currentLink = null
39
-
40
- document.addEventListener('click', (e) => {
41
- const url = e.target.href
42
- if (url && url.endsWith('.js')) {
43
- e.preventDefault()
44
-
45
- fetchContent(url).then(setContent)
46
-
47
- if (currentLink) {
48
- currentLink.classList.remove('active')
49
- }
50
- currentLink = e.target
51
- currentLink.classList.add('active')
52
-
53
- window.location.hash = e.target.pathname
54
- }
55
- })
56
-
57
- const { hash } = window.location
58
- let url = '/examples/basic.js'
59
- if (hash && /^#\/examples\/.+?\.js$/.test(hash)) {
60
- url = hash.slice(1)
61
- }
62
- document.querySelector(`a[href="${url}"]`).click()
63
- }
64
-
65
- initEditor(onSetContent)
66
- init()
@@ -1,25 +0,0 @@
1
- const GIST_PARAM = 'gist'
2
-
3
- export const getQueryParam = (param) => {
4
- return new URL(location.href).searchParams.get(param)
5
- }
6
-
7
- export const clearQueryParam = (param) => {
8
- const path = location.pathname + location.search.replace(new RegExp(`\\b${param}=\\w+`), '').replace(/\?$/, '')
9
- history.pushState({}, '', path)
10
- }
11
-
12
- export const getUrlGistId = () => {
13
- return getQueryParam(GIST_PARAM)
14
- }
15
-
16
- export const setUrlGistId = (id) => {
17
- const path = `${location.pathname}?${GIST_PARAM}=${encodeURIComponent(id)}`
18
- history.pushState({}, '', path)
19
- }
20
-
21
- export const clearUrlGistId = () => {
22
- clearQueryParam(GIST_PARAM)
23
- }
24
-
25
-