@edc4it/reveal.js-external-code 1.0.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/LICENSE +21 -0
- package/README.md +158 -0
- package/dist/code-samples/fibonacci.hs +5 -0
- package/dist/code-samples/k8s.yaml +5 -0
- package/dist/external-code.es.js +402 -0
- package/dist/external-code.umd.js +19 -0
- package/dist/impl/fetcher.d.ts +9 -0
- package/dist/impl/main.d.ts +3 -0
- package/dist/impl/parsers/file-parser.d.ts +8 -0
- package/dist/impl/parsers/range-parser.d.ts +13 -0
- package/dist/impl/stripper.d.ts +8 -0
- package/dist/impl/view/structure.d.ts +34 -0
- package/dist/options.d.ts +21 -0
- package/dist/plugin.d.ts +7 -0
- package/dist/util/dom-utils.d.ts +2 -0
- package/dist/util/file-util.d.ts +1 -0
- package/dist/util/utility-types.d.ts +3 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 EDC4IT B.V.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# Reveal.js External Code
|
|
2
|
+
|
|
3
|
+
[](#)
|
|
4
|
+
|
|
5
|
+
A [reveal.js](https://revealjs.com/) plugin to load code from the server.
|
|
6
|
+
This is helpful when code samples/demos are part
|
|
7
|
+
of your reveal.js presentation.
|
|
8
|
+
This way your demos and slides stay in sync.
|
|
9
|
+
|
|
10
|
+
You will need to run your slides from a server.
|
|
11
|
+
|
|
12
|
+
## Quickstart
|
|
13
|
+
|
|
14
|
+
### Installation
|
|
15
|
+
|
|
16
|
+
This plugin is published to, and can be installed from, npm.
|
|
17
|
+
|
|
18
|
+
```console
|
|
19
|
+
npm install add @edc4it/reveal.js-external-code
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or using yarn
|
|
23
|
+
|
|
24
|
+
```console
|
|
25
|
+
yarn add @edc4it/reveal.js-external-code
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### Initialise (as npm library)
|
|
29
|
+
|
|
30
|
+
```js
|
|
31
|
+
import Reveal from 'reveal.js';
|
|
32
|
+
import RevealHighlight from 'reveal.js/plugin/highlight/highlight';
|
|
33
|
+
import ExternalCode from '@edc4it/reveal.js-external-code';
|
|
34
|
+
|
|
35
|
+
Reveal.initialize({
|
|
36
|
+
externalCode: {},
|
|
37
|
+
plugins: [ExternalCode, RevealHighlight], // makes sure this plugin preceeds Hljs
|
|
38
|
+
});
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Add an external code block
|
|
42
|
+
|
|
43
|
+
Instead of adding `pre > code`, you add an `object[type="reveal.js/code"]`.
|
|
44
|
+
This `object` element will be *replaced* by a wrapper `div.external-code-wrapper` containing `pre > code`.
|
|
45
|
+
You can use any of the `data-*` attributes used by reveal.js (see [docs](https://revealjs.com/code/)); below we are
|
|
46
|
+
adding `data-line-numbers`.
|
|
47
|
+
In fact all attributes will be added to the `pre > code` element (except its `class` attribute, see below).
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
```html
|
|
52
|
+
|
|
53
|
+
<object type="reveal.js/code" data-src="code-samples/k8s.yaml" data-line-numbers="1">
|
|
54
|
+
</object>
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Any known [fragments](https://revealjs.com/fragments/) classes on the `object` are applied to the `div.external-code-wrapper` element.
|
|
58
|
+
|
|
59
|
+
```html
|
|
60
|
+
|
|
61
|
+
<object class="fragment" type="reveal.js/code" data-src="code-samples/k8s.yaml" data-line-numbers="1">
|
|
62
|
+
</object>
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## Limit lines
|
|
66
|
+
|
|
67
|
+
By default, all lines in the `data-src` are displayed (except the one with an optional `@reveal.js/code` annotation, see below).
|
|
68
|
+
You can define a *range* to limit only certain lines.
|
|
69
|
+
Skipped lines are shown using an ellipsis: "…" (Unicode Character U+2026)
|
|
70
|
+
|
|
71
|
+
### Syntax
|
|
72
|
+
|
|
73
|
+
The range is a comma-separate list of:
|
|
74
|
+
- single line number: `n`
|
|
75
|
+
- line range `start-end`
|
|
76
|
+
|
|
77
|
+
Examples:
|
|
78
|
+
|
|
79
|
+
- `1`
|
|
80
|
+
- `1, 5`
|
|
81
|
+
- `1-2, 3`
|
|
82
|
+
- `1-2, 3, 7-9`
|
|
83
|
+
|
|
84
|
+
This range can be set on two levels, in order of precedence:
|
|
85
|
+
|
|
86
|
+
1. inside the file
|
|
87
|
+
2. on the `object[type="reveal.js/code"]` using the `data-lines` attributes
|
|
88
|
+
|
|
89
|
+
### Inside the file:
|
|
90
|
+
|
|
91
|
+
On the first line of the file add a `@reveal.js/code` "annotation"
|
|
92
|
+
(most likely you'll use your code's syntax for a comment as below `--` for Haskel)
|
|
93
|
+
|
|
94
|
+
```haskell
|
|
95
|
+
-- @reveal.js/code
|
|
96
|
+
fib :: Int -> Int
|
|
97
|
+
fib 0 = 0
|
|
98
|
+
fib 1 = 1
|
|
99
|
+
fib n = fib (n - 1) + fib (n - 2)
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
This line is stripped from the resulting code block.
|
|
103
|
+
By itself, this annotation might be helpful to remind yourself that this file is used on slides.
|
|
104
|
+
It can also include a range:
|
|
105
|
+
|
|
106
|
+
```haskell
|
|
107
|
+
-- @reveal.js/code lines=2-4
|
|
108
|
+
fib :: Int -> Int
|
|
109
|
+
fib 0 = 0
|
|
110
|
+
fib 1 = 1
|
|
111
|
+
fib n = fib (n - 1) + fib (n - 2)
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### using teh `data-lines` attribute
|
|
115
|
+
|
|
116
|
+
Below is an example using
|
|
117
|
+
|
|
118
|
+
```html
|
|
119
|
+
|
|
120
|
+
<object type="reveal.js/code"
|
|
121
|
+
data-src="code-samples/k8s.yaml"
|
|
122
|
+
data-lines="1"
|
|
123
|
+
>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
## Global options
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
```javascript
|
|
130
|
+
Reveal.initialize({
|
|
131
|
+
externalCode: {
|
|
132
|
+
basePath: "/",
|
|
133
|
+
enableNotify: true,
|
|
134
|
+
local: {
|
|
135
|
+
absPath: "/home/rparree/projects/foss-edc4it/reveal.js-external-code/public",
|
|
136
|
+
scheme: 'vscode://file//', // default
|
|
137
|
+
},
|
|
138
|
+
codeBlock: {
|
|
139
|
+
trim: true,
|
|
140
|
+
additionalClasses: ["stretch"]
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
},
|
|
145
|
+
plugins: [ExternalCode, RevealHighlight],
|
|
146
|
+
})
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
- `basePath`: path prefix for fetching remote content (`/`)
|
|
150
|
+
- `enableNotify`: enable "toaster" error notification using [simple-notify](https://simple-notify.github.io/simple-notify/) for when the file cannot be loaded (`true`)
|
|
151
|
+
- `local`: configures local copy on the presenter's machine
|
|
152
|
+
- `scheme`: (`'vscode://file//'`)
|
|
153
|
+
- `absPath`: the full path on the local machine (you probably want to use a cookie value for this, so it can be changed)
|
|
154
|
+
- `codeBlock`
|
|
155
|
+
- `trim`: set to `false` to keep whitespace before first character/after last character
|
|
156
|
+
- `additionalClasses`: array of additional css classes to add to the `code` element
|
|
157
|
+
|
|
158
|
+
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".reveal pre,.external-code-wrapper{width:100%}.external-code-wrapper footer.demo-ref{font-size:14px;margin-top:-18px;color:#0d99a5;text-align:right;cursor:help;transition:font-size .4s .1s}.external-code-wrapper footer.demo-ref:before{color:#0d99a5;margin-right:.3em}.external-code-wrapper footer.demo-ref:hover{font-size:28px;cursor:none}")),document.head.appendChild(e)}}catch(r){console.error("vite-plugin-css-injected-by-js",r)}})();
|
|
2
|
+
var J = Object.defineProperty;
|
|
3
|
+
var Q = (e, t, s) => t in e ? J(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
|
|
4
|
+
var _ = (e, t, s) => (Q(e, typeof t != "symbol" ? t + "" : t, s), s);
|
|
5
|
+
class tt extends Error {
|
|
6
|
+
constructor(t) {
|
|
7
|
+
super(t);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
function M(e, t = !1) {
|
|
11
|
+
const s = t ? -1 : 0;
|
|
12
|
+
return e.replace(/\s/g, "").split(",").map((i) => {
|
|
13
|
+
if (/^[\d-]+$/.test(i)) {
|
|
14
|
+
const [o, c] = i.split("-").map((u) => Number.parseInt(u, 10) + s);
|
|
15
|
+
return isNaN(c) ? {
|
|
16
|
+
start: o,
|
|
17
|
+
end: o
|
|
18
|
+
} : {
|
|
19
|
+
start: o,
|
|
20
|
+
end: c
|
|
21
|
+
};
|
|
22
|
+
} else
|
|
23
|
+
throw new tt(`could not parse ${i}`);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
function et(e) {
|
|
27
|
+
var n, i;
|
|
28
|
+
const t = e.split(`
|
|
29
|
+
`), s = t[0];
|
|
30
|
+
if (s.includes("@reveal.js/code")) {
|
|
31
|
+
const o = (i = (n = s.match(/lines=(['"]?(?<range>[\d,\s-]+)['"]?)/)) == null ? void 0 : n.groups) == null ? void 0 : i.range, c = t.slice(1);
|
|
32
|
+
if (o) {
|
|
33
|
+
const l = M(o, !0);
|
|
34
|
+
return {
|
|
35
|
+
lines: c,
|
|
36
|
+
range: l,
|
|
37
|
+
annotated: !0
|
|
38
|
+
};
|
|
39
|
+
} else
|
|
40
|
+
return {
|
|
41
|
+
lines: c,
|
|
42
|
+
annotated: !0
|
|
43
|
+
};
|
|
44
|
+
} else
|
|
45
|
+
return {
|
|
46
|
+
lines: t,
|
|
47
|
+
annotated: !1
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function st(e, t) {
|
|
51
|
+
return e.map((s, n) => nt(n + 1, t) ? s : "…").filter((s, n, i) => !(s === "…" && i[n - 1] === "…"));
|
|
52
|
+
}
|
|
53
|
+
function nt(e, t) {
|
|
54
|
+
return t.find((s) => e >= s.start && e <= s.end) !== void 0;
|
|
55
|
+
}
|
|
56
|
+
function it(e, t) {
|
|
57
|
+
e.parentNode ? e.replaceWith(t) : console.error("The element to be replaced is not attached to the DOM.");
|
|
58
|
+
}
|
|
59
|
+
function rt(e, t) {
|
|
60
|
+
e.forEach((s) => {
|
|
61
|
+
t.setAttribute(s.nodeName, s.nodeValue ?? "");
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
function ot(e) {
|
|
65
|
+
return e.split(".").pop();
|
|
66
|
+
}
|
|
67
|
+
class at {
|
|
68
|
+
constructor(t, s, n, i, a) {
|
|
69
|
+
_(this, "providedLanguage");
|
|
70
|
+
var o;
|
|
71
|
+
this.attributes = t, this.src = s, this.href = n, this.codeStr = i, this.options = a, this.providedLanguage = (o = this.attributes.getNamedItem("data-lang")) == null ? void 0 : o.value;
|
|
72
|
+
}
|
|
73
|
+
create() {
|
|
74
|
+
const { wrapper: t, codeElement: s } = this._createElements(), n = this._codeClasses();
|
|
75
|
+
return s.classList.add(...n), rt([...this.attributes].filter((i) => i.nodeName !== "class"), s), s.innerHTML = this.codeStr, t;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Create the required elements
|
|
79
|
+
* @private
|
|
80
|
+
* @returns the wrapper and the code element for further processing
|
|
81
|
+
*/
|
|
82
|
+
_createElements() {
|
|
83
|
+
const t = this._createWrapper(), s = document.createElement("pre"), n = document.createElement("code"), i = this._footerHtml();
|
|
84
|
+
return t.appendChild(s), s.appendChild(n), s.insertAdjacentHTML("afterend", i), { wrapper: t, codeElement: n };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* constructs the list of classes for the code element
|
|
88
|
+
* @private
|
|
89
|
+
*/
|
|
90
|
+
_codeClasses() {
|
|
91
|
+
const t = ot(this.src), s = this.providedLanguage ?? t ?? "";
|
|
92
|
+
return [...this.options.codeBlock.additionalClasses, s];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Create the footer html with a link to the external code
|
|
96
|
+
* @param preElement
|
|
97
|
+
* @private
|
|
98
|
+
*/
|
|
99
|
+
_footerHtml() {
|
|
100
|
+
var s, n;
|
|
101
|
+
return `<footer class="demo-ref"><a href="${(s = this.options) != null && s.local.absPath ? `${this.options.local.scheme}${(n = this.options) == null ? void 0 : n.local.absPath}/${this.src}` : this.href}">${this.src}</a></footer>`;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Create the outer wrapper
|
|
105
|
+
* @private
|
|
106
|
+
*/
|
|
107
|
+
_createWrapper() {
|
|
108
|
+
var s;
|
|
109
|
+
const t = document.createElement("div");
|
|
110
|
+
return t.classList.add("external-code-wrapper"), t.classList.add(...((s = this.attributes.getNamedItem("class")) == null ? void 0 : s.value.split(" ")) ?? []), t;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async function ct(e, t) {
|
|
114
|
+
const s = await fetch(e);
|
|
115
|
+
if (s.ok) {
|
|
116
|
+
const n = await s.text();
|
|
117
|
+
return t.codeBlock.trim ? n.trim() : n;
|
|
118
|
+
} else
|
|
119
|
+
throw new Error(s.statusText);
|
|
120
|
+
}
|
|
121
|
+
function lt(e, t) {
|
|
122
|
+
if (!(e instanceof t))
|
|
123
|
+
throw new TypeError("Cannot call a class as a function");
|
|
124
|
+
}
|
|
125
|
+
function F(e, t) {
|
|
126
|
+
for (var s = 0; s < t.length; s++) {
|
|
127
|
+
var n = t[s];
|
|
128
|
+
n.enumerable = n.enumerable || !1, n.configurable = !0, "value" in n && (n.writable = !0), Object.defineProperty(e, n.key, n);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function ut(e, t, s) {
|
|
132
|
+
return t && F(e.prototype, t), s && F(e, s), e;
|
|
133
|
+
}
|
|
134
|
+
var dt = Object.defineProperty, d = function(e, t) {
|
|
135
|
+
return dt(e, "name", { value: t, configurable: !0 });
|
|
136
|
+
}, ft = `<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
137
|
+
<path d="m8.94 8 4.2-4.193a.67.67 0 0 0-.947-.947L8 7.06l-4.193-4.2a.67.67 0 1 0-.947.947L7.06 8l-4.2 4.193a.667.667 0 0 0 .217 1.093.666.666 0 0 0 .73-.146L8 8.94l4.193 4.2a.666.666 0 0 0 1.094-.217.665.665 0 0 0-.147-.73L8.94 8Z" fill="currentColor"/>
|
|
138
|
+
</svg>
|
|
139
|
+
`, ht = `<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
140
|
+
<path d="M16 2.667a13.333 13.333 0 1 0 0 26.666 13.333 13.333 0 0 0 0-26.666Zm0 24A10.667 10.667 0 0 1 5.333 16a10.56 10.56 0 0 1 2.254-6.533l14.946 14.946A10.56 10.56 0 0 1 16 26.667Zm8.413-4.134L9.467 7.587A10.56 10.56 0 0 1 16 5.333 10.667 10.667 0 0 1 26.667 16a10.56 10.56 0 0 1-2.254 6.533Z" fill="currentColor"/>
|
|
141
|
+
</svg>
|
|
142
|
+
`, pt = `<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
143
|
+
<path d="M16 14.667A1.333 1.333 0 0 0 14.667 16v5.333a1.333 1.333 0 0 0 2.666 0V16A1.333 1.333 0 0 0 16 14.667Zm.507-5.227a1.333 1.333 0 0 0-1.014 0 1.334 1.334 0 0 0-.44.28 1.56 1.56 0 0 0-.28.44c-.075.158-.11.332-.106.507a1.332 1.332 0 0 0 .386.946c.13.118.279.213.44.28a1.334 1.334 0 0 0 1.84-1.226 1.4 1.4 0 0 0-.386-.947 1.334 1.334 0 0 0-.44-.28ZM16 2.667a13.333 13.333 0 1 0 0 26.666 13.333 13.333 0 0 0 0-26.666Zm0 24a10.666 10.666 0 1 1 0-21.333 10.666 10.666 0 0 1 0 21.333Z" fill="currentColor"/>
|
|
144
|
+
</svg>
|
|
145
|
+
`, mt = `<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
146
|
+
<path d="m19.627 11.72-5.72 5.733-2.2-2.2a1.334 1.334 0 1 0-1.88 1.881l3.133 3.146a1.333 1.333 0 0 0 1.88 0l6.667-6.667a1.333 1.333 0 1 0-1.88-1.893ZM16 2.667a13.333 13.333 0 1 0 0 26.666 13.333 13.333 0 0 0 0-26.666Zm0 24a10.666 10.666 0 1 1 0-21.333 10.666 10.666 0 0 1 0 21.333Z" fill="currentColor"/>
|
|
147
|
+
</svg>
|
|
148
|
+
`, vt = `<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
149
|
+
<path d="M16.334 17.667a1.334 1.334 0 0 0 1.334-1.333v-5.333a1.333 1.333 0 0 0-2.665 0v5.333a1.333 1.333 0 0 0 1.33 1.333Zm-.508 5.227c.325.134.69.134 1.014 0 .165-.064.314-.159.44-.28a1.56 1.56 0 0 0 .28-.44c.076-.158.112-.332.107-.507a1.332 1.332 0 0 0-.387-.946 1.532 1.532 0 0 0-.44-.28 1.334 1.334 0 0 0-1.838 1.226 1.4 1.4 0 0 0 .385.947c.127.121.277.216.44.28Zm.508 6.773a13.333 13.333 0 1 0 0-26.667 13.333 13.333 0 0 0 0 26.667Zm0-24A10.667 10.667 0 1 1 16.54 27a10.667 10.667 0 0 1-.206-21.333Z" fill="currentColor"/>
|
|
150
|
+
</svg>
|
|
151
|
+
`, Ot = d(function(e) {
|
|
152
|
+
return new DOMParser().parseFromString(e, "text/html").body.childNodes[0];
|
|
153
|
+
}, "stringToHTML"), p = d(function(e) {
|
|
154
|
+
var t = new DOMParser().parseFromString(e, "application/xml");
|
|
155
|
+
return document.importNode(t.documentElement, !0).outerHTML;
|
|
156
|
+
}, "getSvgNode"), r = { CONTAINER: "sn-notifications-container", NOTIFY: "sn-notify", NOTIFY_CONTENT: "sn-notify-content", NOTIFY_ICON: "sn-notify-icon", NOTIFY_CLOSE: "sn-notify-close", NOTIFY_TITLE: "sn-notify-title", NOTIFY_TEXT: "sn-notify-text", IS_X_CENTER: "sn-is-x-center", IS_Y_CENTER: "sn-is-y-center", IS_CENTER: "sn-is-center", IS_LEFT: "sn-is-left", IS_RIGHT: "sn-is-right", IS_TOP: "sn-is-top", IS_BOTTOM: "sn-is-bottom", NOTIFY_OUTLINE: "sn-notify-outline", NOTIFY_FILLED: "sn-notify-filled", NOTIFY_ERROR: "sn-notify-error", NOTIFY_WARNING: "sn-notify-warning", NOTIFY_SUCCESS: "sn-notify-success", NOTIFY_INFO: "sn-notify-info", NOTIFY_FADE: "sn-notify-fade", NOTIFY_FADE_IN: "sn-notify-fade-in", NOTIFY_SLIDE: "sn-notify-slide", NOTIFY_SLIDE_IN: "sn-notify-slide-in", NOTIFY_AUTOCLOSE: "sn-notify-autoclose" }, f = { ERROR: "error", WARNING: "warning", SUCCESS: "success", INFO: "info" }, R = { OUTLINE: "outline", FILLED: "filled" }, I = { FADE: "fade", SLIDE: "slide" }, m = { CLOSE: p(ft), SUCCESS: p(mt), ERROR: p(ht), WARNING: p(vt), INFO: p(pt) }, A = d(function(e) {
|
|
157
|
+
e.wrapper.classList.add(r.NOTIFY_FADE), setTimeout(function() {
|
|
158
|
+
e.wrapper.classList.add(r.NOTIFY_FADE_IN);
|
|
159
|
+
}, 100);
|
|
160
|
+
}, "fadeIn"), Y = d(function(e) {
|
|
161
|
+
e.wrapper.classList.remove(r.NOTIFY_FADE_IN), setTimeout(function() {
|
|
162
|
+
e.wrapper.remove();
|
|
163
|
+
}, e.speed);
|
|
164
|
+
}, "fadeOut"), It = d(function(e) {
|
|
165
|
+
e.wrapper.classList.add(r.NOTIFY_SLIDE), setTimeout(function() {
|
|
166
|
+
e.wrapper.classList.add(r.NOTIFY_SLIDE_IN);
|
|
167
|
+
}, 100);
|
|
168
|
+
}, "slideIn"), Et = d(function(e) {
|
|
169
|
+
e.wrapper.classList.remove(r.NOTIFY_SLIDE_IN), setTimeout(function() {
|
|
170
|
+
e.wrapper.remove();
|
|
171
|
+
}, e.speed);
|
|
172
|
+
}, "slideOut"), j = function() {
|
|
173
|
+
function e(t) {
|
|
174
|
+
var s = this;
|
|
175
|
+
lt(this, e), this.notifyOut = d(function(z) {
|
|
176
|
+
z(s);
|
|
177
|
+
}, "notifyOut");
|
|
178
|
+
var n = t.notificationsGap, i = n === void 0 ? 20 : n, a = t.notificationsPadding, o = a === void 0 ? 20 : a, c = t.status, l = c === void 0 ? "success" : c, u = t.effect, E = u === void 0 ? I.FADE : u, O = t.type, k = O === void 0 ? "outline" : O, U = t.title, B = t.text, N = t.showIcon, W = N === void 0 ? !0 : N, y = t.customIcon, Z = y === void 0 ? "" : y, g = t.customClass, G = g === void 0 ? "" : g, T = t.speed, H = T === void 0 ? 500 : T, w = t.showCloseButton, $ = w === void 0 ? !0 : w, b = t.autoclose, q = b === void 0 ? !0 : b, L = t.autotimeout, X = L === void 0 ? 3e3 : L, C = t.position, V = C === void 0 ? "right top" : C, S = t.customWrapper, K = S === void 0 ? "" : S;
|
|
179
|
+
if (this.customWrapper = K, this.status = l, this.title = U, this.text = B, this.showIcon = W, this.customIcon = Z, this.customClass = G, this.speed = H, this.effect = E, this.showCloseButton = $, this.autoclose = q, this.autotimeout = X, this.notificationsGap = i, this.notificationsPadding = o, this.type = k, this.position = V, !this.checkRequirements()) {
|
|
180
|
+
console.error("You must specify 'title' or 'text' at least.");
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
this.setContainer(), this.setWrapper(), this.setPosition(), this.showIcon && this.setIcon(), this.showCloseButton && this.setCloseButton(), this.setContent(), this.container.prepend(this.wrapper), this.setEffect(), this.notifyIn(this.selectedNotifyInEffect), this.autoclose && this.autoClose(), this.setObserver();
|
|
184
|
+
}
|
|
185
|
+
return ut(e, [{ key: "checkRequirements", value: function() {
|
|
186
|
+
return !!(this.title || this.text);
|
|
187
|
+
} }, { key: "setContainer", value: function() {
|
|
188
|
+
var s = document.querySelector(".".concat(r.CONTAINER));
|
|
189
|
+
s ? this.container = s : (this.container = document.createElement("div"), this.container.classList.add(r.CONTAINER), document.body.appendChild(this.container)), this.notificationsPadding && this.container.style.setProperty("--sn-notifications-padding", "".concat(this.notificationsPadding, "px")), this.notificationsGap && this.container.style.setProperty("--sn-notifications-gap", "".concat(this.notificationsGap, "px"));
|
|
190
|
+
} }, { key: "setPosition", value: function() {
|
|
191
|
+
this.container.classList[this.position === "center" ? "add" : "remove"](r.IS_CENTER), this.container.classList[this.position.includes("left") ? "add" : "remove"](r.IS_LEFT), this.container.classList[this.position.includes("right") ? "add" : "remove"](r.IS_RIGHT), this.container.classList[this.position.includes("top") ? "add" : "remove"](r.IS_TOP), this.container.classList[this.position.includes("bottom") ? "add" : "remove"](r.IS_BOTTOM), this.container.classList[this.position.includes("x-center") ? "add" : "remove"](r.IS_X_CENTER), this.container.classList[this.position.includes("y-center") ? "add" : "remove"](r.IS_Y_CENTER);
|
|
192
|
+
} }, { key: "setCloseButton", value: function() {
|
|
193
|
+
var s = this, n = document.createElement("div");
|
|
194
|
+
n.classList.add(r.NOTIFY_CLOSE), n.innerHTML = m.CLOSE, this.wrapper.appendChild(n), n.addEventListener("click", function() {
|
|
195
|
+
s.close();
|
|
196
|
+
});
|
|
197
|
+
} }, { key: "setWrapper", value: function() {
|
|
198
|
+
var s = this;
|
|
199
|
+
switch (this.customWrapper ? this.wrapper = Ot(this.customWrapper) : this.wrapper = document.createElement("div"), this.wrapper.style.setProperty("--sn-notify-transition-duration", "".concat(this.speed, "ms")), this.wrapper.classList.add(r.NOTIFY), this.type) {
|
|
200
|
+
case R.OUTLINE:
|
|
201
|
+
this.wrapper.classList.add(r.NOTIFY_OUTLINE);
|
|
202
|
+
break;
|
|
203
|
+
case R.FILLED:
|
|
204
|
+
this.wrapper.classList.add(r.NOTIFY_FILLED);
|
|
205
|
+
break;
|
|
206
|
+
default:
|
|
207
|
+
this.wrapper.classList.add(r.NOTIFY_OUTLINE);
|
|
208
|
+
}
|
|
209
|
+
switch (this.status) {
|
|
210
|
+
case f.SUCCESS:
|
|
211
|
+
this.wrapper.classList.add(r.NOTIFY_SUCCESS);
|
|
212
|
+
break;
|
|
213
|
+
case f.ERROR:
|
|
214
|
+
this.wrapper.classList.add(r.NOTIFY_ERROR);
|
|
215
|
+
break;
|
|
216
|
+
case f.WARNING:
|
|
217
|
+
this.wrapper.classList.add(r.NOTIFY_WARNING);
|
|
218
|
+
break;
|
|
219
|
+
case f.INFO:
|
|
220
|
+
this.wrapper.classList.add(r.NOTIFY_INFO);
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
this.autoclose && (this.wrapper.classList.add(r.NOTIFY_AUTOCLOSE), this.wrapper.style.setProperty("--sn-notify-autoclose-timeout", "".concat(this.autotimeout + this.speed, "ms"))), this.customClass && this.customClass.split(" ").forEach(function(n) {
|
|
224
|
+
s.wrapper.classList.add(n);
|
|
225
|
+
});
|
|
226
|
+
} }, { key: "setContent", value: function() {
|
|
227
|
+
var s = document.createElement("div");
|
|
228
|
+
s.classList.add(r.NOTIFY_CONTENT);
|
|
229
|
+
var n, i;
|
|
230
|
+
this.title && (n = document.createElement("div"), n.classList.add(r.NOTIFY_TITLE), n.textContent = this.title.trim(), this.showCloseButton || (n.style.paddingRight = "0")), this.text && (i = document.createElement("div"), i.classList.add(r.NOTIFY_TEXT), i.innerHTML = this.text.trim(), this.title || (i.style.marginTop = "0")), this.wrapper.appendChild(s), this.title && s.appendChild(n), this.text && s.appendChild(i);
|
|
231
|
+
} }, { key: "setIcon", value: function() {
|
|
232
|
+
var s = d(function(i) {
|
|
233
|
+
switch (i) {
|
|
234
|
+
case f.SUCCESS:
|
|
235
|
+
return m.SUCCESS;
|
|
236
|
+
case f.ERROR:
|
|
237
|
+
return m.ERROR;
|
|
238
|
+
case f.WARNING:
|
|
239
|
+
return m.WARNING;
|
|
240
|
+
case f.INFO:
|
|
241
|
+
return m.INFO;
|
|
242
|
+
}
|
|
243
|
+
}, "computedIcon"), n = document.createElement("div");
|
|
244
|
+
n.classList.add(r.NOTIFY_ICON), n.innerHTML = this.customIcon || s(this.status), (this.status || this.customIcon) && this.wrapper.appendChild(n);
|
|
245
|
+
} }, { key: "setObserver", value: function() {
|
|
246
|
+
var s = this, n = new IntersectionObserver(function(i) {
|
|
247
|
+
if (i[0].intersectionRatio <= 0)
|
|
248
|
+
s.close();
|
|
249
|
+
else
|
|
250
|
+
return;
|
|
251
|
+
}, { threshold: 0 });
|
|
252
|
+
setTimeout(function() {
|
|
253
|
+
n.observe(s.wrapper);
|
|
254
|
+
}, this.speed);
|
|
255
|
+
} }, { key: "notifyIn", value: function(t) {
|
|
256
|
+
t(this);
|
|
257
|
+
} }, { key: "autoClose", value: function() {
|
|
258
|
+
var s = this;
|
|
259
|
+
setTimeout(function() {
|
|
260
|
+
s.close();
|
|
261
|
+
}, this.autotimeout + this.speed);
|
|
262
|
+
} }, { key: "close", value: function() {
|
|
263
|
+
this.notifyOut(this.selectedNotifyOutEffect);
|
|
264
|
+
} }, { key: "setEffect", value: function() {
|
|
265
|
+
switch (this.effect) {
|
|
266
|
+
case I.FADE:
|
|
267
|
+
this.selectedNotifyInEffect = A, this.selectedNotifyOutEffect = Y;
|
|
268
|
+
break;
|
|
269
|
+
case I.SLIDE:
|
|
270
|
+
this.selectedNotifyInEffect = It, this.selectedNotifyOutEffect = Et;
|
|
271
|
+
break;
|
|
272
|
+
default:
|
|
273
|
+
this.selectedNotifyInEffect = A, this.selectedNotifyOutEffect = Y;
|
|
274
|
+
}
|
|
275
|
+
} }]), e;
|
|
276
|
+
}();
|
|
277
|
+
d(j, "Notify");
|
|
278
|
+
var P = j;
|
|
279
|
+
globalThis.Notify = P;
|
|
280
|
+
function Nt(e, t) {
|
|
281
|
+
const { range: s, lines: n, annotated: i } = et(e), a = t ? M(t, i) : void 0, o = s ?? a;
|
|
282
|
+
return (o ? st(n, o) : n).join(`
|
|
283
|
+
`);
|
|
284
|
+
}
|
|
285
|
+
async function yt(e, t) {
|
|
286
|
+
const s = e.querySelectorAll("object[type='reveal.js/code']"), n = Array.from(s).map(async (i) => {
|
|
287
|
+
const a = i.getAttribute("data-src"), o = i.getAttribute("data-lines");
|
|
288
|
+
if (a) {
|
|
289
|
+
const c = `./${t.basePath}/${a}`;
|
|
290
|
+
try {
|
|
291
|
+
const l = await ct(c, t);
|
|
292
|
+
if (l) {
|
|
293
|
+
const u = Nt(l, o), O = new at(i.attributes, a, c, u, t).create();
|
|
294
|
+
it(i, O);
|
|
295
|
+
}
|
|
296
|
+
} catch (l) {
|
|
297
|
+
const u = `exception while processing external code ${a}`;
|
|
298
|
+
t.enableNotify && new P({ text: u }), console.error(u, l);
|
|
299
|
+
}
|
|
300
|
+
} else
|
|
301
|
+
console.error("object[type='reveal.js/code'] has no src attribute", i);
|
|
302
|
+
});
|
|
303
|
+
return Promise.all(n);
|
|
304
|
+
}
|
|
305
|
+
function gt(e) {
|
|
306
|
+
return e && e.__esModule && Object.prototype.hasOwnProperty.call(e, "default") ? e.default : e;
|
|
307
|
+
}
|
|
308
|
+
var Tt = function(t) {
|
|
309
|
+
return wt(t) && !bt(t);
|
|
310
|
+
};
|
|
311
|
+
function wt(e) {
|
|
312
|
+
return !!e && typeof e == "object";
|
|
313
|
+
}
|
|
314
|
+
function bt(e) {
|
|
315
|
+
var t = Object.prototype.toString.call(e);
|
|
316
|
+
return t === "[object RegExp]" || t === "[object Date]" || St(e);
|
|
317
|
+
}
|
|
318
|
+
var Lt = typeof Symbol == "function" && Symbol.for, Ct = Lt ? Symbol.for("react.element") : 60103;
|
|
319
|
+
function St(e) {
|
|
320
|
+
return e.$$typeof === Ct;
|
|
321
|
+
}
|
|
322
|
+
function _t(e) {
|
|
323
|
+
return Array.isArray(e) ? [] : {};
|
|
324
|
+
}
|
|
325
|
+
function v(e, t) {
|
|
326
|
+
return t.clone !== !1 && t.isMergeableObject(e) ? h(_t(e), e, t) : e;
|
|
327
|
+
}
|
|
328
|
+
function Ft(e, t, s) {
|
|
329
|
+
return e.concat(t).map(function(n) {
|
|
330
|
+
return v(n, s);
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
function Rt(e, t) {
|
|
334
|
+
if (!t.customMerge)
|
|
335
|
+
return h;
|
|
336
|
+
var s = t.customMerge(e);
|
|
337
|
+
return typeof s == "function" ? s : h;
|
|
338
|
+
}
|
|
339
|
+
function At(e) {
|
|
340
|
+
return Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols(e).filter(function(t) {
|
|
341
|
+
return Object.propertyIsEnumerable.call(e, t);
|
|
342
|
+
}) : [];
|
|
343
|
+
}
|
|
344
|
+
function x(e) {
|
|
345
|
+
return Object.keys(e).concat(At(e));
|
|
346
|
+
}
|
|
347
|
+
function D(e, t) {
|
|
348
|
+
try {
|
|
349
|
+
return t in e;
|
|
350
|
+
} catch {
|
|
351
|
+
return !1;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
function Yt(e, t) {
|
|
355
|
+
return D(e, t) && !(Object.hasOwnProperty.call(e, t) && Object.propertyIsEnumerable.call(e, t));
|
|
356
|
+
}
|
|
357
|
+
function xt(e, t, s) {
|
|
358
|
+
var n = {};
|
|
359
|
+
return s.isMergeableObject(e) && x(e).forEach(function(i) {
|
|
360
|
+
n[i] = v(e[i], s);
|
|
361
|
+
}), x(t).forEach(function(i) {
|
|
362
|
+
Yt(e, i) || (D(e, i) && s.isMergeableObject(t[i]) ? n[i] = Rt(i, s)(e[i], t[i], s) : n[i] = v(t[i], s));
|
|
363
|
+
}), n;
|
|
364
|
+
}
|
|
365
|
+
function h(e, t, s) {
|
|
366
|
+
s = s || {}, s.arrayMerge = s.arrayMerge || Ft, s.isMergeableObject = s.isMergeableObject || Tt, s.cloneUnlessOtherwiseSpecified = v;
|
|
367
|
+
var n = Array.isArray(t), i = Array.isArray(e), a = n === i;
|
|
368
|
+
return a ? n ? s.arrayMerge(e, t, s) : xt(e, t, s) : v(t, s);
|
|
369
|
+
}
|
|
370
|
+
h.all = function(t, s) {
|
|
371
|
+
if (!Array.isArray(t))
|
|
372
|
+
throw new Error("first argument should be an array");
|
|
373
|
+
return t.reduce(function(n, i) {
|
|
374
|
+
return h(n, i, s);
|
|
375
|
+
}, {});
|
|
376
|
+
};
|
|
377
|
+
var Mt = h, jt = Mt;
|
|
378
|
+
const Pt = /* @__PURE__ */ gt(jt), Dt = {
|
|
379
|
+
basePath: "/",
|
|
380
|
+
enableNotify: !0,
|
|
381
|
+
codeBlock: {
|
|
382
|
+
trim: !0,
|
|
383
|
+
additionalClasses: []
|
|
384
|
+
},
|
|
385
|
+
local: {
|
|
386
|
+
scheme: "vscode://file//"
|
|
387
|
+
}
|
|
388
|
+
}, Ut = () => ({
|
|
389
|
+
id: "external-code",
|
|
390
|
+
init: (e) => {
|
|
391
|
+
const t = e.getRevealElement();
|
|
392
|
+
if (!t)
|
|
393
|
+
console.error("Cannot find reveal element");
|
|
394
|
+
else {
|
|
395
|
+
const n = e.getConfig().externalCode ?? {}, i = Pt(Dt, n);
|
|
396
|
+
return yt(t, i);
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
export {
|
|
401
|
+
Ut as default
|
|
402
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
(function(){"use strict";try{if(typeof document<"u"){var e=document.createElement("style");e.appendChild(document.createTextNode(".reveal pre,.external-code-wrapper{width:100%}.external-code-wrapper footer.demo-ref{font-size:14px;margin-top:-18px;color:#0d99a5;text-align:right;cursor:help;transition:font-size .4s .1s}.external-code-wrapper footer.demo-ref:before{color:#0d99a5;margin-right:.3em}.external-code-wrapper footer.demo-ref:hover{font-size:28px;cursor:none}")),document.head.appendChild(e)}}catch(r){console.error("vite-plugin-css-injected-by-js",r)}})();
|
|
2
|
+
(function(u,c){typeof exports=="object"&&typeof module<"u"?module.exports=c():typeof define=="function"&&define.amd?define(c):(u=typeof globalThis<"u"?globalThis:u||self,u.ClipCode=c())})(this,function(){"use strict";var Pt=Object.defineProperty;var Dt=(u,c,m)=>c in u?Pt(u,c,{enumerable:!0,configurable:!0,writable:!0,value:m}):u[c]=m;var U=(u,c,m)=>(Dt(u,typeof c!="symbol"?c+"":c,m),m);class u extends Error{constructor(t){super(t)}}function c(e,t=!1){const s=t?-1:0;return e.replace(/\s/g,"").split(",").map(i=>{if(/^[\d-]+$/.test(i)){const[o,l]=i.split("-").map(h=>Number.parseInt(h,10)+s);return isNaN(l)?{start:o,end:o}:{start:o,end:l}}else throw new u(`could not parse ${i}`)})}function m(e){var n,i;const t=e.split(`
|
|
3
|
+
`),s=t[0];if(s.includes("@reveal.js/code")){const o=(i=(n=s.match(/lines=(['"]?(?<range>[\d,\s-]+)['"]?)/))==null?void 0:n.groups)==null?void 0:i.range,l=t.slice(1);if(o){const f=c(o,!0);return{lines:l,range:f,annotated:!0}}else return{lines:l,annotated:!0}}else return{lines:t,annotated:!1}}function B(e,t){return e.map((s,n)=>W(n+1,t)?s:"…").filter((s,n,i)=>!(s==="…"&&i[n-1]==="…"))}function W(e,t){return t.find(s=>e>=s.start&&e<=s.end)!==void 0}function Z(e,t){e.parentNode?e.replaceWith(t):console.error("The element to be replaced is not attached to the DOM.")}function G(e,t){e.forEach(s=>{t.setAttribute(s.nodeName,s.nodeValue??"")})}function H(e){return e.split(".").pop()}class ${constructor(t,s,n,i,a){U(this,"providedLanguage");var o;this.attributes=t,this.src=s,this.href=n,this.codeStr=i,this.options=a,this.providedLanguage=(o=this.attributes.getNamedItem("data-lang"))==null?void 0:o.value}create(){const{wrapper:t,codeElement:s}=this._createElements(),n=this._codeClasses();return s.classList.add(...n),G([...this.attributes].filter(i=>i.nodeName!=="class"),s),s.innerHTML=this.codeStr,t}_createElements(){const t=this._createWrapper(),s=document.createElement("pre"),n=document.createElement("code"),i=this._footerHtml();return t.appendChild(s),s.appendChild(n),s.insertAdjacentHTML("afterend",i),{wrapper:t,codeElement:n}}_codeClasses(){const t=H(this.src),s=this.providedLanguage??t??"";return[...this.options.codeBlock.additionalClasses,s]}_footerHtml(){var s,n;return`<footer class="demo-ref"><a href="${(s=this.options)!=null&&s.local.absPath?`${this.options.local.scheme}${(n=this.options)==null?void 0:n.local.absPath}/${this.src}`:this.href}">${this.src}</a></footer>`}_createWrapper(){var s;const t=document.createElement("div");return t.classList.add("external-code-wrapper"),t.classList.add(...((s=this.attributes.getNamedItem("class"))==null?void 0:s.value.split(" "))??[]),t}}async function q(e,t){const s=await fetch(e);if(s.ok){const n=await s.text();return t.codeBlock.trim?n.trim():n}else throw new Error(s.statusText)}function X(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function g(e,t){for(var s=0;s<t.length;s++){var n=t[s];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function V(e,t,s){return t&&g(e.prototype,t),s&&g(e,s),e}var K=Object.defineProperty,d=function(e,t){return K(e,"name",{value:t,configurable:!0})},z=`<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
4
|
+
<path d="m8.94 8 4.2-4.193a.67.67 0 0 0-.947-.947L8 7.06l-4.193-4.2a.67.67 0 1 0-.947.947L7.06 8l-4.2 4.193a.667.667 0 0 0 .217 1.093.666.666 0 0 0 .73-.146L8 8.94l4.193 4.2a.666.666 0 0 0 1.094-.217.665.665 0 0 0-.147-.73L8.94 8Z" fill="currentColor"/>
|
|
5
|
+
</svg>
|
|
6
|
+
`,J=`<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
7
|
+
<path d="M16 2.667a13.333 13.333 0 1 0 0 26.666 13.333 13.333 0 0 0 0-26.666Zm0 24A10.667 10.667 0 0 1 5.333 16a10.56 10.56 0 0 1 2.254-6.533l14.946 14.946A10.56 10.56 0 0 1 16 26.667Zm8.413-4.134L9.467 7.587A10.56 10.56 0 0 1 16 5.333 10.667 10.667 0 0 1 26.667 16a10.56 10.56 0 0 1-2.254 6.533Z" fill="currentColor"/>
|
|
8
|
+
</svg>
|
|
9
|
+
`,Q=`<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
10
|
+
<path d="M16 14.667A1.333 1.333 0 0 0 14.667 16v5.333a1.333 1.333 0 0 0 2.666 0V16A1.333 1.333 0 0 0 16 14.667Zm.507-5.227a1.333 1.333 0 0 0-1.014 0 1.334 1.334 0 0 0-.44.28 1.56 1.56 0 0 0-.28.44c-.075.158-.11.332-.106.507a1.332 1.332 0 0 0 .386.946c.13.118.279.213.44.28a1.334 1.334 0 0 0 1.84-1.226 1.4 1.4 0 0 0-.386-.947 1.334 1.334 0 0 0-.44-.28ZM16 2.667a13.333 13.333 0 1 0 0 26.666 13.333 13.333 0 0 0 0-26.666Zm0 24a10.666 10.666 0 1 1 0-21.333 10.666 10.666 0 0 1 0 21.333Z" fill="currentColor"/>
|
|
11
|
+
</svg>
|
|
12
|
+
`,tt=`<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
13
|
+
<path d="m19.627 11.72-5.72 5.733-2.2-2.2a1.334 1.334 0 1 0-1.88 1.881l3.133 3.146a1.333 1.333 0 0 0 1.88 0l6.667-6.667a1.333 1.333 0 1 0-1.88-1.893ZM16 2.667a13.333 13.333 0 1 0 0 26.666 13.333 13.333 0 0 0 0-26.666Zm0 24a10.666 10.666 0 1 1 0-21.333 10.666 10.666 0 0 1 0 21.333Z" fill="currentColor"/>
|
|
14
|
+
</svg>
|
|
15
|
+
`,et=`<svg width="32" height="32" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
16
|
+
<path d="M16.334 17.667a1.334 1.334 0 0 0 1.334-1.333v-5.333a1.333 1.333 0 0 0-2.665 0v5.333a1.333 1.333 0 0 0 1.33 1.333Zm-.508 5.227c.325.134.69.134 1.014 0 .165-.064.314-.159.44-.28a1.56 1.56 0 0 0 .28-.44c.076-.158.112-.332.107-.507a1.332 1.332 0 0 0-.387-.946 1.532 1.532 0 0 0-.44-.28 1.334 1.334 0 0 0-1.838 1.226 1.4 1.4 0 0 0 .385.947c.127.121.277.216.44.28Zm.508 6.773a13.333 13.333 0 1 0 0-26.667 13.333 13.333 0 0 0 0 26.667Zm0-24A10.667 10.667 0 1 1 16.54 27a10.667 10.667 0 0 1-.206-21.333Z" fill="currentColor"/>
|
|
17
|
+
</svg>
|
|
18
|
+
`,st=d(function(e){return new DOMParser().parseFromString(e,"text/html").body.childNodes[0]},"stringToHTML"),O=d(function(e){var t=new DOMParser().parseFromString(e,"application/xml");return document.importNode(t.documentElement,!0).outerHTML},"getSvgNode"),r={CONTAINER:"sn-notifications-container",NOTIFY:"sn-notify",NOTIFY_CONTENT:"sn-notify-content",NOTIFY_ICON:"sn-notify-icon",NOTIFY_CLOSE:"sn-notify-close",NOTIFY_TITLE:"sn-notify-title",NOTIFY_TEXT:"sn-notify-text",IS_X_CENTER:"sn-is-x-center",IS_Y_CENTER:"sn-is-y-center",IS_CENTER:"sn-is-center",IS_LEFT:"sn-is-left",IS_RIGHT:"sn-is-right",IS_TOP:"sn-is-top",IS_BOTTOM:"sn-is-bottom",NOTIFY_OUTLINE:"sn-notify-outline",NOTIFY_FILLED:"sn-notify-filled",NOTIFY_ERROR:"sn-notify-error",NOTIFY_WARNING:"sn-notify-warning",NOTIFY_SUCCESS:"sn-notify-success",NOTIFY_INFO:"sn-notify-info",NOTIFY_FADE:"sn-notify-fade",NOTIFY_FADE_IN:"sn-notify-fade-in",NOTIFY_SLIDE:"sn-notify-slide",NOTIFY_SLIDE_IN:"sn-notify-slide-in",NOTIFY_AUTOCLOSE:"sn-notify-autoclose"},p={ERROR:"error",WARNING:"warning",SUCCESS:"success",INFO:"info"},T={OUTLINE:"outline",FILLED:"filled"},y={FADE:"fade",SLIDE:"slide"},I={CLOSE:O(z),SUCCESS:O(tt),ERROR:O(J),WARNING:O(et),INFO:O(Q)},w=d(function(e){e.wrapper.classList.add(r.NOTIFY_FADE),setTimeout(function(){e.wrapper.classList.add(r.NOTIFY_FADE_IN)},100)},"fadeIn"),b=d(function(e){e.wrapper.classList.remove(r.NOTIFY_FADE_IN),setTimeout(function(){e.wrapper.remove()},e.speed)},"fadeOut"),nt=d(function(e){e.wrapper.classList.add(r.NOTIFY_SLIDE),setTimeout(function(){e.wrapper.classList.add(r.NOTIFY_SLIDE_IN)},100)},"slideIn"),it=d(function(e){e.wrapper.classList.remove(r.NOTIFY_SLIDE_IN),setTimeout(function(){e.wrapper.remove()},e.speed)},"slideOut"),L=function(){function e(t){var s=this;X(this,e),this.notifyOut=d(function(jt){jt(s)},"notifyOut");var n=t.notificationsGap,i=n===void 0?20:n,a=t.notificationsPadding,o=a===void 0?20:a,l=t.status,f=l===void 0?"success":l,h=t.effect,F=h===void 0?y.FADE:h,N=t.type,wt=N===void 0?"outline":N,bt=t.title,Lt=t.text,R=t.showIcon,Ct=R===void 0?!0:R,A=t.customIcon,St=A===void 0?"":A,Y=t.customClass,_t=Y===void 0?"":Y,x=t.speed,Ft=x===void 0?500:x,M=t.showCloseButton,Rt=M===void 0?!0:M,j=t.autoclose,At=j===void 0?!0:j,P=t.autotimeout,Yt=P===void 0?3e3:P,D=t.position,xt=D===void 0?"right top":D,k=t.customWrapper,Mt=k===void 0?"":k;if(this.customWrapper=Mt,this.status=f,this.title=bt,this.text=Lt,this.showIcon=Ct,this.customIcon=St,this.customClass=_t,this.speed=Ft,this.effect=F,this.showCloseButton=Rt,this.autoclose=At,this.autotimeout=Yt,this.notificationsGap=i,this.notificationsPadding=o,this.type=wt,this.position=xt,!this.checkRequirements()){console.error("You must specify 'title' or 'text' at least.");return}this.setContainer(),this.setWrapper(),this.setPosition(),this.showIcon&&this.setIcon(),this.showCloseButton&&this.setCloseButton(),this.setContent(),this.container.prepend(this.wrapper),this.setEffect(),this.notifyIn(this.selectedNotifyInEffect),this.autoclose&&this.autoClose(),this.setObserver()}return V(e,[{key:"checkRequirements",value:function(){return!!(this.title||this.text)}},{key:"setContainer",value:function(){var s=document.querySelector(".".concat(r.CONTAINER));s?this.container=s:(this.container=document.createElement("div"),this.container.classList.add(r.CONTAINER),document.body.appendChild(this.container)),this.notificationsPadding&&this.container.style.setProperty("--sn-notifications-padding","".concat(this.notificationsPadding,"px")),this.notificationsGap&&this.container.style.setProperty("--sn-notifications-gap","".concat(this.notificationsGap,"px"))}},{key:"setPosition",value:function(){this.container.classList[this.position==="center"?"add":"remove"](r.IS_CENTER),this.container.classList[this.position.includes("left")?"add":"remove"](r.IS_LEFT),this.container.classList[this.position.includes("right")?"add":"remove"](r.IS_RIGHT),this.container.classList[this.position.includes("top")?"add":"remove"](r.IS_TOP),this.container.classList[this.position.includes("bottom")?"add":"remove"](r.IS_BOTTOM),this.container.classList[this.position.includes("x-center")?"add":"remove"](r.IS_X_CENTER),this.container.classList[this.position.includes("y-center")?"add":"remove"](r.IS_Y_CENTER)}},{key:"setCloseButton",value:function(){var s=this,n=document.createElement("div");n.classList.add(r.NOTIFY_CLOSE),n.innerHTML=I.CLOSE,this.wrapper.appendChild(n),n.addEventListener("click",function(){s.close()})}},{key:"setWrapper",value:function(){var s=this;switch(this.customWrapper?this.wrapper=st(this.customWrapper):this.wrapper=document.createElement("div"),this.wrapper.style.setProperty("--sn-notify-transition-duration","".concat(this.speed,"ms")),this.wrapper.classList.add(r.NOTIFY),this.type){case T.OUTLINE:this.wrapper.classList.add(r.NOTIFY_OUTLINE);break;case T.FILLED:this.wrapper.classList.add(r.NOTIFY_FILLED);break;default:this.wrapper.classList.add(r.NOTIFY_OUTLINE)}switch(this.status){case p.SUCCESS:this.wrapper.classList.add(r.NOTIFY_SUCCESS);break;case p.ERROR:this.wrapper.classList.add(r.NOTIFY_ERROR);break;case p.WARNING:this.wrapper.classList.add(r.NOTIFY_WARNING);break;case p.INFO:this.wrapper.classList.add(r.NOTIFY_INFO);break}this.autoclose&&(this.wrapper.classList.add(r.NOTIFY_AUTOCLOSE),this.wrapper.style.setProperty("--sn-notify-autoclose-timeout","".concat(this.autotimeout+this.speed,"ms"))),this.customClass&&this.customClass.split(" ").forEach(function(n){s.wrapper.classList.add(n)})}},{key:"setContent",value:function(){var s=document.createElement("div");s.classList.add(r.NOTIFY_CONTENT);var n,i;this.title&&(n=document.createElement("div"),n.classList.add(r.NOTIFY_TITLE),n.textContent=this.title.trim(),this.showCloseButton||(n.style.paddingRight="0")),this.text&&(i=document.createElement("div"),i.classList.add(r.NOTIFY_TEXT),i.innerHTML=this.text.trim(),this.title||(i.style.marginTop="0")),this.wrapper.appendChild(s),this.title&&s.appendChild(n),this.text&&s.appendChild(i)}},{key:"setIcon",value:function(){var s=d(function(i){switch(i){case p.SUCCESS:return I.SUCCESS;case p.ERROR:return I.ERROR;case p.WARNING:return I.WARNING;case p.INFO:return I.INFO}},"computedIcon"),n=document.createElement("div");n.classList.add(r.NOTIFY_ICON),n.innerHTML=this.customIcon||s(this.status),(this.status||this.customIcon)&&this.wrapper.appendChild(n)}},{key:"setObserver",value:function(){var s=this,n=new IntersectionObserver(function(i){if(i[0].intersectionRatio<=0)s.close();else return},{threshold:0});setTimeout(function(){n.observe(s.wrapper)},this.speed)}},{key:"notifyIn",value:function(t){t(this)}},{key:"autoClose",value:function(){var s=this;setTimeout(function(){s.close()},this.autotimeout+this.speed)}},{key:"close",value:function(){this.notifyOut(this.selectedNotifyOutEffect)}},{key:"setEffect",value:function(){switch(this.effect){case y.FADE:this.selectedNotifyInEffect=w,this.selectedNotifyOutEffect=b;break;case y.SLIDE:this.selectedNotifyInEffect=nt,this.selectedNotifyOutEffect=it;break;default:this.selectedNotifyInEffect=w,this.selectedNotifyOutEffect=b}}}]),e}();d(L,"Notify");var C=L;globalThis.Notify=C;function rt(e,t){const{range:s,lines:n,annotated:i}=m(e),a=t?c(t,i):void 0,o=s??a;return(o?B(n,o):n).join(`
|
|
19
|
+
`)}async function ot(e,t){const s=e.querySelectorAll("object[type='reveal.js/code']"),n=Array.from(s).map(async i=>{const a=i.getAttribute("data-src"),o=i.getAttribute("data-lines");if(a){const l=`./${t.basePath}/${a}`;try{const f=await q(l,t);if(f){const h=rt(f,o),N=new $(i.attributes,a,l,h,t).create();Z(i,N)}}catch(f){const h=`exception while processing external code ${a}`;t.enableNotify&&new C({text:h}),console.error(h,f)}}else console.error("object[type='reveal.js/code'] has no src attribute",i)});return Promise.all(n)}function at(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ct=function(t){return lt(t)&&!ut(t)};function lt(e){return!!e&&typeof e=="object"}function ut(e){var t=Object.prototype.toString.call(e);return t==="[object RegExp]"||t==="[object Date]"||ht(e)}var dt=typeof Symbol=="function"&&Symbol.for,ft=dt?Symbol.for("react.element"):60103;function ht(e){return e.$$typeof===ft}function pt(e){return Array.isArray(e)?[]:{}}function E(e,t){return t.clone!==!1&&t.isMergeableObject(e)?v(pt(e),e,t):e}function mt(e,t,s){return e.concat(t).map(function(n){return E(n,s)})}function vt(e,t){if(!t.customMerge)return v;var s=t.customMerge(e);return typeof s=="function"?s:v}function Ot(e){return Object.getOwnPropertySymbols?Object.getOwnPropertySymbols(e).filter(function(t){return Object.propertyIsEnumerable.call(e,t)}):[]}function S(e){return Object.keys(e).concat(Ot(e))}function _(e,t){try{return t in e}catch{return!1}}function It(e,t){return _(e,t)&&!(Object.hasOwnProperty.call(e,t)&&Object.propertyIsEnumerable.call(e,t))}function Et(e,t,s){var n={};return s.isMergeableObject(e)&&S(e).forEach(function(i){n[i]=E(e[i],s)}),S(t).forEach(function(i){It(e,i)||(_(e,i)&&s.isMergeableObject(t[i])?n[i]=vt(i,s)(e[i],t[i],s):n[i]=E(t[i],s))}),n}function v(e,t,s){s=s||{},s.arrayMerge=s.arrayMerge||mt,s.isMergeableObject=s.isMergeableObject||ct,s.cloneUnlessOtherwiseSpecified=E;var n=Array.isArray(t),i=Array.isArray(e),a=n===i;return a?n?s.arrayMerge(e,t,s):Et(e,t,s):E(t,s)}v.all=function(t,s){if(!Array.isArray(t))throw new Error("first argument should be an array");return t.reduce(function(n,i){return v(n,i,s)},{})};var Nt=v,yt=Nt;const gt=at(yt),Tt={basePath:"/",enableNotify:!0,codeBlock:{trim:!0,additionalClasses:[]},local:{scheme:"vscode://file//"}};return()=>({id:"external-code",init:e=>{const t=e.getRevealElement();if(!t)console.error("Cannot find reveal element");else{const n=e.getConfig().externalCode??{},i=gt(Tt,n);return ot(t,i)}}})});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { Options } from '../options.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* fetch the code from the server
|
|
5
|
+
* @throws an Error when res.ok is false (and passes on native fetch errors)
|
|
6
|
+
* @param url A string that provides the URL of the resource you want to fetch.
|
|
7
|
+
* @param options
|
|
8
|
+
*/
|
|
9
|
+
export declare function fetchCode(url: string, options: Options): Promise<string>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type Range = {
|
|
2
|
+
start: number;
|
|
3
|
+
end: number;
|
|
4
|
+
};
|
|
5
|
+
export declare class RangeParseError extends Error {
|
|
6
|
+
constructor(m: string);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param ranges comma-seperated ranges
|
|
11
|
+
* @param adjust if to shift the range by -1 (e.g., because of stripping `@reveal.js/code`)
|
|
12
|
+
*/
|
|
13
|
+
export declare function parseRange(ranges: string, adjust?: boolean): Range[];
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Options } from '../../options.ts';
|
|
2
|
+
|
|
3
|
+
export declare class Structure {
|
|
4
|
+
private readonly attributes;
|
|
5
|
+
private readonly src;
|
|
6
|
+
private readonly href;
|
|
7
|
+
private readonly codeStr;
|
|
8
|
+
private readonly options;
|
|
9
|
+
private readonly providedLanguage?;
|
|
10
|
+
constructor(attributes: NamedNodeMap, src: string, href: string, codeStr: string, options: Pick<Options, 'local' | 'codeBlock'>);
|
|
11
|
+
create(): HTMLDivElement;
|
|
12
|
+
/**
|
|
13
|
+
* Create the required elements
|
|
14
|
+
* @private
|
|
15
|
+
* @returns the wrapper and the code element for further processing
|
|
16
|
+
*/
|
|
17
|
+
private _createElements;
|
|
18
|
+
/**
|
|
19
|
+
* constructs the list of classes for the code element
|
|
20
|
+
* @private
|
|
21
|
+
*/
|
|
22
|
+
private _codeClasses;
|
|
23
|
+
/**
|
|
24
|
+
* Create the footer html with a link to the external code
|
|
25
|
+
* @param preElement
|
|
26
|
+
* @private
|
|
27
|
+
*/
|
|
28
|
+
private _footerHtml;
|
|
29
|
+
/**
|
|
30
|
+
* Create the outer wrapper
|
|
31
|
+
* @private
|
|
32
|
+
*/
|
|
33
|
+
private _createWrapper;
|
|
34
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { DeepPartial } from './util/utility-types.ts';
|
|
2
|
+
import { Options as RevealOptions } from 'reveal.js';
|
|
3
|
+
|
|
4
|
+
export type CodeBlockOptions = {
|
|
5
|
+
trim: boolean;
|
|
6
|
+
additionalClasses: string[];
|
|
7
|
+
};
|
|
8
|
+
export type LocalOptions = {
|
|
9
|
+
scheme: 'vscode://file//' | string;
|
|
10
|
+
absPath?: string;
|
|
11
|
+
};
|
|
12
|
+
export type Options = {
|
|
13
|
+
basePath: string;
|
|
14
|
+
local: LocalOptions;
|
|
15
|
+
codeBlock: CodeBlockOptions;
|
|
16
|
+
enableNotify: boolean;
|
|
17
|
+
};
|
|
18
|
+
export declare const defaultOptions: Options;
|
|
19
|
+
export type AugmentedRevealOptions = RevealOptions & {
|
|
20
|
+
externalCode?: DeepPartial<Options>;
|
|
21
|
+
};
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function getFileSuffix(src: string): string | undefined;
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@edc4it/reveal.js-external-code",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"keywords": [
|
|
5
|
+
"reveal",
|
|
6
|
+
"reveal.js",
|
|
7
|
+
"reveal-plugin",
|
|
8
|
+
"plugin",
|
|
9
|
+
"railroad",
|
|
10
|
+
"syntax",
|
|
11
|
+
"diagrams"
|
|
12
|
+
],
|
|
13
|
+
"version": "1.0.2",
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"author": "Raphaël Parrée <rparree@edc4it.com> (https://www.edc4it.com/)",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/edc4it/reveal.js-external-code.git"
|
|
21
|
+
},
|
|
22
|
+
"main": "./dist/external-code.umd.js",
|
|
23
|
+
"module": "./dist/external-code.es.js",
|
|
24
|
+
"scripts": {
|
|
25
|
+
"dev": "vite",
|
|
26
|
+
"build": "tsc && vite build",
|
|
27
|
+
"test": "vitest",
|
|
28
|
+
"preview": "vite preview",
|
|
29
|
+
"lint": "eslint . --ext .ts,.tsx",
|
|
30
|
+
"prepare": "husky"
|
|
31
|
+
},
|
|
32
|
+
"lint-staged": {
|
|
33
|
+
"*.ts": "eslint --cache --fix"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@types/reveal.js": "^5.0.1",
|
|
37
|
+
"@typescript-eslint/eslint-plugin": "^7.4.0",
|
|
38
|
+
"@typescript-eslint/parser": "^7.4.0",
|
|
39
|
+
"autoprefixer": "^10.4.19",
|
|
40
|
+
"eslint": "^8.57.0",
|
|
41
|
+
"eslint-plugin-import": "^2.29.1",
|
|
42
|
+
"husky": "^9.0.11",
|
|
43
|
+
"lint-staged": "^15.2.2",
|
|
44
|
+
"postcss-nesting": "^12.1.0",
|
|
45
|
+
"typescript": "^5.2.2",
|
|
46
|
+
"vite": "^5.2.0",
|
|
47
|
+
"vite-plugin-css-injected-by-js": "^3.5.0",
|
|
48
|
+
"vite-plugin-dts": "^3.8.0",
|
|
49
|
+
"vite-plugin-remove-console": "^2.2.0",
|
|
50
|
+
"vitest": "^1.4.0"
|
|
51
|
+
},
|
|
52
|
+
"dependencies": {
|
|
53
|
+
"deepmerge": "^4.3.1",
|
|
54
|
+
"reveal.js": "^5.0.5",
|
|
55
|
+
"simple-notify": "^1.0.4"
|
|
56
|
+
},
|
|
57
|
+
"bugs": {
|
|
58
|
+
"url": "https://github.com/edc4it/reveal.js-external-code/issues"
|
|
59
|
+
},
|
|
60
|
+
"homepage": "https://github.com/edc4it/reveal.js-external-code#readme",
|
|
61
|
+
"description": ""
|
|
62
|
+
}
|