@canopycanopycanopy/b-ber-parser-gallery 3.0.8-next.61 → 3.0.8-next.96
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/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +203 -201
- package/package.json +16 -18
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":";cA0IM,eAAA,GAAmB,EAAA,OAAS,IAAA,UAAc,OAAA;AAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,214 +1,216 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
let _canopycanopycanopy_b_ber_grammar_attributes = require("@canopycanopycanopy/b-ber-grammar-attributes");
|
|
24
|
+
let _canopycanopycanopy_b_ber_lib = require("@canopycanopycanopy/b-ber-lib");
|
|
25
|
+
let mime_types = require("mime-types");
|
|
26
|
+
mime_types = __toESM(mime_types);
|
|
27
|
+
let path = require("path");
|
|
28
|
+
path = __toESM(path);
|
|
29
|
+
//#region src/index.ts
|
|
18
30
|
/*!
|
|
19
31
|
An adapted version of markdown-it-container 2.0.0
|
|
20
32
|
https://github.com//markdown-it/markdown-it-container
|
|
21
33
|
MIT license
|
|
22
34
|
*/
|
|
23
|
-
|
|
24
35
|
const addCaption = (md, t, attrs) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
36
|
+
if (!attrs.caption) return;
|
|
37
|
+
t.children.push({
|
|
38
|
+
type: "block",
|
|
39
|
+
tag: "div",
|
|
40
|
+
attrs: [["class", "figcaption"], ["data-caption", (0, _canopycanopycanopy_b_ber_grammar_attributes.htmlId)(attrs.source)]],
|
|
41
|
+
nesting: 1
|
|
42
|
+
}, {
|
|
43
|
+
type: "block",
|
|
44
|
+
tag: "p",
|
|
45
|
+
attrs: [["class", "small"]],
|
|
46
|
+
nesting: 1
|
|
47
|
+
}, ...md.parseInline(attrs.caption, {})[0].children, {
|
|
48
|
+
type: "block",
|
|
49
|
+
tag: "p",
|
|
50
|
+
nesting: -1
|
|
51
|
+
}, {
|
|
52
|
+
type: "block",
|
|
53
|
+
tag: "div",
|
|
54
|
+
nesting: -1
|
|
55
|
+
});
|
|
45
56
|
};
|
|
46
57
|
const createImageElement = (tok, attrs) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
58
|
+
tok.content = "";
|
|
59
|
+
tok.children.push({
|
|
60
|
+
type: "inline",
|
|
61
|
+
tag: "img",
|
|
62
|
+
attrs: [
|
|
63
|
+
["data-image", (0, _canopycanopycanopy_b_ber_grammar_attributes.htmlId)(attrs.source)],
|
|
64
|
+
["src", `../images/${encodeURIComponent(attrs.source)}`],
|
|
65
|
+
["alt", attrs.alt || attrs.source]
|
|
66
|
+
],
|
|
67
|
+
nesting: 0
|
|
68
|
+
});
|
|
54
69
|
};
|
|
55
70
|
const createMediaElement = (tok, attrs) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
71
|
+
const media = [..._canopycanopycanopy_b_ber_lib.State[attrs.type]];
|
|
72
|
+
const supportedMediaAttrs = {
|
|
73
|
+
audio: ["controls", "loop"],
|
|
74
|
+
video: [
|
|
75
|
+
"controls",
|
|
76
|
+
"loop",
|
|
77
|
+
"fullscreen"
|
|
78
|
+
]
|
|
79
|
+
};
|
|
80
|
+
const sources = media.filter((a) => (0, _canopycanopycanopy_b_ber_grammar_attributes.toAlias)(a) === attrs.source);
|
|
81
|
+
const mediaAttrs = [[`data-${attrs.type}`, (0, _canopycanopycanopy_b_ber_grammar_attributes.htmlId)(attrs.source)]];
|
|
82
|
+
if (attrs.poster) mediaAttrs.push(["poster", `../images/${attrs.poster}`]);
|
|
83
|
+
supportedMediaAttrs[attrs.type].forEach((a) => {
|
|
84
|
+
if (attrs[a]) mediaAttrs.push([a, a]);
|
|
85
|
+
});
|
|
86
|
+
tok.content = "";
|
|
87
|
+
tok.children.push({
|
|
88
|
+
type: "block",
|
|
89
|
+
tag: "section",
|
|
90
|
+
attrs: [["class", attrs.type]],
|
|
91
|
+
nesting: 1
|
|
92
|
+
}, {
|
|
93
|
+
type: "block",
|
|
94
|
+
tag: attrs.type,
|
|
95
|
+
attrs: mediaAttrs,
|
|
96
|
+
nesting: 1
|
|
97
|
+
});
|
|
98
|
+
sources.forEach((source) => {
|
|
99
|
+
tok.children.push({
|
|
100
|
+
type: "inline",
|
|
101
|
+
tag: "source",
|
|
102
|
+
attrs: [["src", `../media/${path.default.basename(source)}`], ["type", mime_types.default.lookup(source)]],
|
|
103
|
+
nesting: 0
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
tok.children.push({
|
|
107
|
+
type: "block",
|
|
108
|
+
tag: attrs.type,
|
|
109
|
+
nesting: -1
|
|
110
|
+
}, {
|
|
111
|
+
type: "inline",
|
|
112
|
+
tag: "button",
|
|
113
|
+
attrs: [
|
|
114
|
+
["data-media-type", attrs.type],
|
|
115
|
+
["data-media-controls", (0, _canopycanopycanopy_b_ber_grammar_attributes.htmlId)(attrs.source)],
|
|
116
|
+
["class", "media__controls media__controls--play"]
|
|
117
|
+
],
|
|
118
|
+
nesting: 0
|
|
119
|
+
}, {
|
|
120
|
+
type: "block",
|
|
121
|
+
tag: "section",
|
|
122
|
+
nesting: -1
|
|
123
|
+
});
|
|
105
124
|
};
|
|
106
125
|
const containerPlugin = (md, name, options = {}) => {
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
case 'video':
|
|
196
|
-
case 'audio':
|
|
197
|
-
createMediaElement(tok, attrs);
|
|
198
|
-
addCaption(md, tok, attrs);
|
|
199
|
-
break;
|
|
200
|
-
default:
|
|
201
|
-
break;
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
return true;
|
|
207
|
-
}
|
|
208
|
-
md.block.ruler.before('fence', `container_${name}`, container, {
|
|
209
|
-
alt: ['paragraph', 'reference', 'blockquote']
|
|
210
|
-
});
|
|
211
|
-
md.renderer.rules[`container_${name}_open`] = render;
|
|
212
|
-
md.renderer.rules[`container_${name}_close`] = render;
|
|
126
|
+
const minMarkers = options.minMarkers || 3;
|
|
127
|
+
const markerStr = options.marker || ":";
|
|
128
|
+
const markerChar = markerStr.charCodeAt(0);
|
|
129
|
+
const markerLen = markerStr.length;
|
|
130
|
+
const { validateOpen, render } = options;
|
|
131
|
+
function container(state, startLine, endLine, silent) {
|
|
132
|
+
const lineNumber = startLine + 1;
|
|
133
|
+
let pos;
|
|
134
|
+
let nextLine;
|
|
135
|
+
let token;
|
|
136
|
+
let autoClosed = false;
|
|
137
|
+
let start = state.bMarks[startLine] + state.tShift[startLine];
|
|
138
|
+
let max = state.eMarks[startLine];
|
|
139
|
+
if (markerChar !== state.src.charCodeAt(start)) return false;
|
|
140
|
+
for (pos = start + 1; pos <= max; pos++) if (markerStr[(pos - start) % markerLen] !== state.src[pos]) break;
|
|
141
|
+
const markerCount = Math.floor((pos - start) / markerLen);
|
|
142
|
+
if (markerCount < minMarkers) return false;
|
|
143
|
+
pos -= (pos - start) % markerLen;
|
|
144
|
+
const markup = state.src.slice(start, pos);
|
|
145
|
+
const params = state.src.slice(pos, max);
|
|
146
|
+
if (!validateOpen(params, lineNumber)) return false;
|
|
147
|
+
if (silent) return true;
|
|
148
|
+
nextLine = startLine;
|
|
149
|
+
for (;;) {
|
|
150
|
+
nextLine += 1;
|
|
151
|
+
if (nextLine >= endLine) break;
|
|
152
|
+
start = state.bMarks[nextLine] + state.tShift[nextLine];
|
|
153
|
+
max = state.eMarks[nextLine];
|
|
154
|
+
if (state.sCount[nextLine] - state.blkIndent >= 4) continue;
|
|
155
|
+
if (Math.floor((pos - start) / markerLen) < markerCount) continue;
|
|
156
|
+
if (pos < max) continue;
|
|
157
|
+
autoClosed = true;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
const oldParent = state.parentType;
|
|
161
|
+
const oldLineMax = state.lineMax;
|
|
162
|
+
state.parentType = "container";
|
|
163
|
+
state.lineMax = nextLine;
|
|
164
|
+
token = state.push(`container_${name}_open`, "div", 1);
|
|
165
|
+
token.markup = markup;
|
|
166
|
+
token.block = true;
|
|
167
|
+
token.info = params;
|
|
168
|
+
token.map = [startLine, nextLine];
|
|
169
|
+
state.md.block.tokenize(state, startLine + 1, nextLine);
|
|
170
|
+
token = state.push(`container_${name}_close`, "div", -1);
|
|
171
|
+
token.markup = state.src.slice(start, pos);
|
|
172
|
+
token.block = true;
|
|
173
|
+
state.parentType = oldParent;
|
|
174
|
+
state.lineMax = oldLineMax;
|
|
175
|
+
state.line = nextLine + (autoClosed ? 1 : 0);
|
|
176
|
+
let childOfGallery = false;
|
|
177
|
+
state.tokens.forEach((tok, i) => {
|
|
178
|
+
if (tok.type === "container_gallery_open") childOfGallery = true;
|
|
179
|
+
if (tok.type === "container_gallery_close") childOfGallery = false;
|
|
180
|
+
if (tok.type === "inline" && childOfGallery) {
|
|
181
|
+
const matchedContent = tok.content.match(/^(::\s?(.+)\s?::)/);
|
|
182
|
+
if (matchedContent) {
|
|
183
|
+
const attrs = (0, _canopycanopycanopy_b_ber_grammar_attributes.parseAttrs)(matchedContent[1]);
|
|
184
|
+
const prev = state.tokens[i - 1];
|
|
185
|
+
const next = state.tokens[i + 1];
|
|
186
|
+
prev.tag = "div";
|
|
187
|
+
prev.attrSet("class", "gallery__item");
|
|
188
|
+
prev.attrSet("data-gallery-item", attrs.item);
|
|
189
|
+
next.tag = "div";
|
|
190
|
+
switch (attrs.type) {
|
|
191
|
+
case "image":
|
|
192
|
+
createImageElement(tok, attrs);
|
|
193
|
+
addCaption(md, tok, attrs);
|
|
194
|
+
break;
|
|
195
|
+
case "video":
|
|
196
|
+
case "audio":
|
|
197
|
+
createMediaElement(tok, attrs);
|
|
198
|
+
addCaption(md, tok, attrs);
|
|
199
|
+
break;
|
|
200
|
+
default: break;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
return true;
|
|
206
|
+
}
|
|
207
|
+
md.block.ruler.before("fence", `container_${name}`, container, { alt: [
|
|
208
|
+
"paragraph",
|
|
209
|
+
"reference",
|
|
210
|
+
"blockquote"
|
|
211
|
+
] });
|
|
212
|
+
md.renderer.rules[`container_${name}_open`] = render;
|
|
213
|
+
md.renderer.rules[`container_${name}_close`] = render;
|
|
213
214
|
};
|
|
214
|
-
|
|
215
|
+
//#endregion
|
|
216
|
+
module.exports = containerPlugin;
|
package/package.json
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canopycanopycanopy/b-ber-parser-gallery",
|
|
3
|
-
"version": "3.0.8-next.
|
|
3
|
+
"version": "3.0.8-next.96+7446845b",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
6
7
|
"scripts": {
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"prepare": "npm run clean && npm run prepare:dist",
|
|
10
|
-
"build": "npm run prepare",
|
|
11
|
-
"watch": "BABEL_ENV=production babel --config-file ../../babel.config.js -d dist/ src/ --watch src",
|
|
8
|
+
"build": "tsdown",
|
|
9
|
+
"typecheck": "tsc --noEmit",
|
|
12
10
|
"test": "jest"
|
|
13
11
|
},
|
|
14
12
|
"author": "Triple Canopy <b-ber@canopycanopycanopy.com> (https://triplecanopy.github.io/)",
|
|
@@ -17,19 +15,19 @@
|
|
|
17
15
|
"access": "public"
|
|
18
16
|
},
|
|
19
17
|
"devDependencies": {
|
|
20
|
-
"@
|
|
21
|
-
"@
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
18
|
+
"@swc/core": "^1.15.40",
|
|
19
|
+
"@swc/jest": "^0.2.39",
|
|
20
|
+
"jest": "^29.7.0",
|
|
21
|
+
"rimraf": "^2.7.1",
|
|
22
|
+
"tsdown": "^0.22.1",
|
|
23
|
+
"typescript": "^6.0.3"
|
|
26
24
|
},
|
|
27
25
|
"dependencies": {
|
|
28
|
-
"@canopycanopycanopy/b-ber-grammar-attributes": "3.0.8-next.
|
|
29
|
-
"@canopycanopycanopy/b-ber-lib": "3.0.8-next.
|
|
30
|
-
"@canopycanopycanopy/b-ber-logger": "3.0.8-next.
|
|
31
|
-
"@canopycanopycanopy/b-ber-shapes-directives": "3.0.8-next.
|
|
32
|
-
"@canopycanopycanopy/b-ber-templates": "3.0.8-next.
|
|
26
|
+
"@canopycanopycanopy/b-ber-grammar-attributes": "3.0.8-next.96+7446845b",
|
|
27
|
+
"@canopycanopycanopy/b-ber-lib": "3.0.8-next.96+7446845b",
|
|
28
|
+
"@canopycanopycanopy/b-ber-logger": "3.0.8-next.96+7446845b",
|
|
29
|
+
"@canopycanopycanopy/b-ber-shapes-directives": "3.0.8-next.96+7446845b",
|
|
30
|
+
"@canopycanopycanopy/b-ber-templates": "3.0.8-next.96+7446845b",
|
|
33
31
|
"lodash": "^4.17.21",
|
|
34
32
|
"mime-types": "^2.1.24",
|
|
35
33
|
"tar": "^6.1.11"
|
|
@@ -51,5 +49,5 @@
|
|
|
51
49
|
"url": "https://maxwellsimmer.com"
|
|
52
50
|
}
|
|
53
51
|
],
|
|
54
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "7446845bcda4337bfbc9f75b55a1e0ca805023eb"
|
|
55
53
|
}
|