@canopycanopycanopy/b-ber-parser-gallery 3.0.8-next.61 → 3.0.8-next.97

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.
@@ -0,0 +1,4 @@
1
+ //#region src/index.d.ts
2
+ declare const containerPlugin: (md: any, name: string, options?: any) => void;
3
+ export = containerPlugin;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -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
- "use strict";
2
-
3
- var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
5
- _Object$defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.default = void 0;
9
- var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
10
- var _forEach = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/for-each"));
11
- var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
12
- var _path = _interopRequireDefault(require("path"));
13
- var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
14
- var _mimeTypes = _interopRequireDefault(require("mime-types"));
15
- var _bBerGrammarAttributes = require("@canopycanopycanopy/b-ber-grammar-attributes");
16
- /* eslint-disable no-param-reassign,no-continue */
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
- if (!attrs.caption) return;
26
- t.children.push({
27
- type: 'block',
28
- tag: 'div',
29
- attrs: [['class', 'figcaption'], ['data-caption', (0, _bBerGrammarAttributes.htmlId)(attrs.source)]],
30
- nesting: 1
31
- }, {
32
- type: 'block',
33
- tag: 'p',
34
- attrs: [['class', 'small']],
35
- nesting: 1
36
- }, ...md.parseInline(attrs.caption, {})[0].children, {
37
- type: 'block',
38
- tag: 'p',
39
- nesting: -1
40
- }, {
41
- type: 'block',
42
- tag: 'div',
43
- nesting: -1
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
- tok.content = '';
48
- tok.children.push({
49
- type: 'inline',
50
- tag: 'img',
51
- attrs: [['data-image', (0, _bBerGrammarAttributes.htmlId)(attrs.source)], ['src', `../images/${encodeURIComponent(attrs.source)}`], ['alt', attrs.alt || attrs.source]],
52
- nesting: 0
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
- var _context;
57
- const media = [..._State.default[attrs.type]];
58
- const supportedMediaAttrs = {
59
- audio: ['controls', 'loop'],
60
- video: ['controls', 'loop', 'fullscreen']
61
- };
62
- const sources = (0, _filter.default)(media).call(media, a => (0, _bBerGrammarAttributes.toAlias)(a) === attrs.source);
63
- const mediaAttrs = [[`data-${attrs.type}`, (0, _bBerGrammarAttributes.htmlId)(attrs.source)]];
64
- if (attrs.poster) mediaAttrs.push(['poster', `../images/${attrs.poster}`]);
65
-
66
- // add boolean attrs
67
- (0, _forEach.default)(_context = supportedMediaAttrs[attrs.type]).call(_context, a => {
68
- if (attrs[a]) mediaAttrs.push([a, a]);
69
- });
70
- tok.content = '';
71
- tok.children.push({
72
- type: 'block',
73
- tag: 'section',
74
- attrs: [['class', attrs.type]],
75
- nesting: 1
76
- }, {
77
- type: 'block',
78
- tag: attrs.type,
79
- attrs: mediaAttrs,
80
- nesting: 1
81
- });
82
- (0, _forEach.default)(sources).call(sources, source => {
83
- tok.children.push({
84
- type: 'inline',
85
- tag: 'source',
86
- attrs: [['src', `../media/${_path.default.basename(source)}`], ['type', _mimeTypes.default.lookup(source)]],
87
- nesting: 0
88
- });
89
- });
90
- tok.children.push({
91
- type: 'block',
92
- tag: attrs.type,
93
- nesting: -1
94
- }, {
95
- type: 'inline',
96
- // controls. TODO: add to media core directive
97
- tag: 'button',
98
- attrs: [['data-media-type', attrs.type], ['data-media-controls', (0, _bBerGrammarAttributes.htmlId)(attrs.source)], ['class', 'media__controls media__controls--play']],
99
- nesting: 0
100
- }, {
101
- type: 'block',
102
- tag: 'section',
103
- nesting: -1
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
- const minMarkers = options.minMarkers || 3;
108
- const markerStr = options.marker || ':';
109
- const markerChar = markerStr.charCodeAt(0);
110
- const markerLen = markerStr.length;
111
- const {
112
- validateOpen,
113
- render
114
- } = options;
115
- function container(state, startLine, endLine, silent) {
116
- var _context2, _context3, _context4, _context5;
117
- const lineNumber = startLine + 1;
118
- let pos;
119
- let nextLine;
120
- let token;
121
- let autoClosed = false;
122
- let start = state.bMarks[startLine] + state.tShift[startLine];
123
- let max = state.eMarks[startLine];
124
- if (markerChar !== state.src.charCodeAt(start)) return false;
125
-
126
- // Check out the rest of the marker string, i.e., count the number of markers
127
- for (pos = start + 1; pos <= max; pos++) {
128
- if (markerStr[(pos - start) % markerLen] !== state.src[pos]) {
129
- break;
130
- }
131
- }
132
- const markerCount = Math.floor((pos - start) / markerLen);
133
- if (markerCount < minMarkers) return false;
134
- pos -= (pos - start) % markerLen;
135
- const markup = (0, _slice.default)(_context2 = state.src).call(_context2, start, pos);
136
- const params = (0, _slice.default)(_context3 = state.src).call(_context3, pos, max);
137
- if (!validateOpen(params, lineNumber)) return false;
138
- if (silent) return true; // for testing validation
139
-
140
- nextLine = startLine;
141
-
142
- // look for closing block
143
- for (;;) {
144
- nextLine += 1;
145
- if (nextLine >= endLine) break; // unclosed block is autoclosed by end of document
146
-
147
- start = state.bMarks[nextLine] + state.tShift[nextLine];
148
- max = state.eMarks[nextLine];
149
- if (state.sCount[nextLine] - state.blkIndent >= 4) continue; // closing fence must be indented less than 4 spaces
150
- if (Math.floor((pos - start) / markerLen) < markerCount) continue;
151
- if (pos < max) continue;
152
- autoClosed = true;
153
- break;
154
- }
155
- const oldParent = state.parentType;
156
- const oldLineMax = state.lineMax;
157
- state.parentType = 'container';
158
-
159
- // this will prevent lazy continuations from ever going past our end marker
160
- state.lineMax = nextLine;
161
- token = state.push(`container_${name}_open`, 'div', 1);
162
- token.markup = markup;
163
- token.block = true;
164
- token.info = params;
165
- token.map = [startLine, nextLine];
166
- state.md.block.tokenize(state, startLine + 1, nextLine);
167
- token = state.push(`container_${name}_close`, 'div', -1);
168
- token.markup = (0, _slice.default)(_context4 = state.src).call(_context4, start, pos);
169
- token.block = true;
170
- state.parentType = oldParent;
171
- state.lineMax = oldLineMax;
172
- state.line = nextLine + (autoClosed ? 1 : 0);
173
-
174
- // parse child tokens
175
- // set a flag so that we don't render other directives' children which may use the same syntax
176
- let childOfGallery = false;
177
- (0, _forEach.default)(_context5 = state.tokens).call(_context5, (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, _bBerGrammarAttributes.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:
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
- var _default = exports.default = containerPlugin;
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.61+2bbec564",
3
+ "version": "3.0.8-next.97+2e9748e6",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
6
7
  "scripts": {
7
- "prepare:dist": "BABEL_ENV=production babel --config-file ../../babel.config.js -d dist/ src/ --ignore **/__tests__/**",
8
- "clean": "rimraf dist",
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
- "@babel/cli": "^7.10.5",
21
- "@babel/core": "^7.10.5",
22
- "@babel/preset-env": "^7.10.4",
23
- "browserslist": "^4.17.4",
24
- "jest": "^26.6.3",
25
- "rimraf": "^2.7.1"
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.61+2bbec564",
29
- "@canopycanopycanopy/b-ber-lib": "3.0.8-next.61+2bbec564",
30
- "@canopycanopycanopy/b-ber-logger": "3.0.8-next.61+2bbec564",
31
- "@canopycanopycanopy/b-ber-shapes-directives": "3.0.8-next.61+2bbec564",
32
- "@canopycanopycanopy/b-ber-templates": "3.0.8-next.61+2bbec564",
26
+ "@canopycanopycanopy/b-ber-grammar-attributes": "3.0.8-next.97+2e9748e6",
27
+ "@canopycanopycanopy/b-ber-lib": "3.0.8-next.97+2e9748e6",
28
+ "@canopycanopycanopy/b-ber-logger": "3.0.8-next.97+2e9748e6",
29
+ "@canopycanopycanopy/b-ber-shapes-directives": "3.0.8-next.97+2e9748e6",
30
+ "@canopycanopycanopy/b-ber-templates": "3.0.8-next.97+2e9748e6",
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": "2bbec5643278f53becb0d2ba1f55edfe379d5587"
52
+ "gitHead": "2e9748e6f00446cd35dc8f933e049d8200fc24dd"
55
53
  }