@canopycanopycanopy/b-ber-grammar-iframe 3.0.8-nav-memo.4 → 3.0.8-next.100

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/README.md CHANGED
@@ -1,9 +1,20 @@
1
- # `@canopycanopycanopy/b-ber-grammar-iframe`
1
+ # b-ber-grammar-iframe
2
2
 
3
- The `b-ber-grammar-iframe` package renders b-ber's custom `iframe` Markdown extensions (directives) into HTML. More information about b-ber directives can be found in the [All directives](https://github.com/triplecanopy/b-ber/wiki/all-directives) page in the b-ber [Wiki](https://github.com/triplecanopy/b-ber/wiki).
3
+ Handles the `iframe` and `iframe-inline` custom Markdown directives. The `iframe` form adds the embed to the figures list (state) and emits a small linked thumbnail pointing to a generated figure page, for display in the List of Illustrations. The `iframe-inline` form emits a fully rendered `<iframe>` element inline in the content — but only for `reader` and `web` builds; other build targets receive an unsupported-content placeholder. Attributes such as `height`, `width`, `title`, `poster`, and standard iframe attributes are parsed and forwarded to the rendered element. Uses `b-ber-parser-figure` as the MarkdownIt plugin.
4
4
 
5
- ## Install
5
+ ## Usage
6
6
 
7
+ Registered as a MarkdownIt plugin by the rendering engine:
8
+
9
+ ```js
10
+ import iframe from '@canopycanopycanopy/b-ber-grammar-iframe'
11
+ // { plugin, name: 'iframe', renderer }
7
12
  ```
8
- $ npm i -g @canopycanopycanopy/b-ber-grammar-iframe
13
+
14
+ ## Dev
15
+
9
16
  ```
17
+ npm test
18
+ ```
19
+
20
+ Tests are in `__tests__/index.test.js`.
@@ -0,0 +1,19 @@
1
+ //#region src/index.d.ts
2
+ declare const _default: {
3
+ plugin: (md: any, name: string, options?: any) => void;
4
+ name: string;
5
+ renderer: ({
6
+ instance,
7
+ context
8
+ }: {
9
+ instance: any;
10
+ context: any;
11
+ }) => {
12
+ marker: string;
13
+ minMarkers: number;
14
+ validate: (params: any) => any;
15
+ render: (tokens: any, index: any) => string;
16
+ };
17
+ };
18
+ export = _default;
19
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/index.ts"],"mappings":""}
package/dist/index.js CHANGED
@@ -1,67 +1,142 @@
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 _trim = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/trim"));
10
- var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
11
- var _utils = require("@canopycanopycanopy/b-ber-lib/utils");
12
- var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
13
- var _bBerShapesDirectives = require("@canopycanopycanopy/b-ber-shapes-directives");
14
- var _bBerParserFigure = _interopRequireDefault(require("@canopycanopycanopy/b-ber-parser-figure"));
15
- var _helpers = require("./helpers");
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_lib = require("@canopycanopycanopy/b-ber-lib");
24
+ let _canopycanopycanopy_b_ber_parser_figure = require("@canopycanopycanopy/b-ber-parser-figure");
25
+ _canopycanopycanopy_b_ber_parser_figure = __toESM(_canopycanopycanopy_b_ber_parser_figure);
26
+ let _canopycanopycanopy_b_ber_shapes_directives = require("@canopycanopycanopy/b-ber-shapes-directives");
27
+ let _canopycanopycanopy_b_ber_grammar_attributes = require("@canopycanopycanopy/b-ber-grammar-attributes");
28
+ let _canopycanopycanopy_b_ber_lib_utils = require("@canopycanopycanopy/b-ber-lib/utils");
29
+ //#region src/helpers.ts
30
+ function supported(build) {
31
+ return build === "reader" || build === "web";
32
+ }
33
+ function prepare({ token, marker, context, instance, fileName, lineNumber }) {
34
+ const [, type, id, attrs] = marker;
35
+ const mediaType = (0, _canopycanopycanopy_b_ber_lib_utils.getMediaType)(type);
36
+ const figureId = (0, _canopycanopycanopy_b_ber_grammar_attributes.htmlId)(id);
37
+ const page = `figure-${figureId}.xhtml`;
38
+ const attrsObject = {
39
+ source: "",
40
+ height: 150,
41
+ width: "100%",
42
+ title: "",
43
+ classes: "",
44
+ poster: "",
45
+ ...(0, _canopycanopycanopy_b_ber_grammar_attributes.attributesObject)(attrs, type, {
46
+ fileName,
47
+ lineNumber
48
+ })
49
+ };
50
+ (0, _canopycanopycanopy_b_ber_lib_utils.ensureSource)(attrsObject, type, fileName, lineNumber);
51
+ (0, _canopycanopycanopy_b_ber_lib_utils.ensurePoster)(attrsObject, type);
52
+ (0, _canopycanopycanopy_b_ber_lib_utils.ensureSupportedClassNames)(attrsObject, supported);
53
+ return {
54
+ ...attrsObject,
55
+ id: figureId,
56
+ attrString: (0, _canopycanopycanopy_b_ber_grammar_attributes.attributesString)(attrsObject, { classes: true }),
57
+ commentStart: _canopycanopycanopy_b_ber_lib.Html.comment(`START: ${mediaType}:${type}#${figureId};`),
58
+ commentEnd: _canopycanopycanopy_b_ber_lib.Html.comment(`END: ${mediaType}:${type}#${figureId};`),
59
+ href: _canopycanopycanopy_b_ber_lib.State.build === "reader" ? "figures-titlepage.xhtml" : page,
60
+ ref: context.fileName,
61
+ caption: token.children ? instance.renderInline(token.children) : "",
62
+ page,
63
+ type,
64
+ mediaType,
65
+ mime: null,
66
+ pageOrder: _canopycanopycanopy_b_ber_lib.State.figures.length,
67
+ source: _canopycanopycanopy_b_ber_lib.Url.ensureDecoded(attrsObject.source),
68
+ poster: attrsObject.poster
69
+ };
70
+ }
71
+ function createIframe({ id, href, poster }) {
72
+ return `
73
+ <div class="figure__small figure__small--landscape">
74
+ <figure id="ref${id}">
75
+ <a href="${href}#${id}">
76
+ ${(0, _canopycanopycanopy_b_ber_lib_utils.renderPosterImage)(poster)}
77
+ </a>
78
+ </figure>
79
+ </div>`;
80
+ }
81
+ function createIframeInline(data) {
82
+ const { id, commentStart, commentEnd, mediaType, attrString: containerAttrsString, source, caption, ...rest } = data;
83
+ return `
84
+ ${commentStart}
85
+ <section class="${mediaType} figure__large figure__inline">
86
+ <div id="${id}"${containerAttrsString}>
87
+ <iframe src="${source}" ${Object.entries({
88
+ allow: "fullscreen autoplay",
89
+ ...rest
90
+ }).reduce((acc, [key, val]) => {
91
+ if (!_canopycanopycanopy_b_ber_shapes_directives.htmlIframeAttributes.has(key) || val === "") return acc;
92
+ return acc.concat(`${key}="${val}"`);
93
+ }, []).join(" ")}>
94
+ </iframe>
95
+ </div>
96
+ ${(0, _canopycanopycanopy_b_ber_lib_utils.renderCaption)(caption, mediaType)}
97
+ </section>
98
+ ${commentEnd}`;
99
+ }
100
+ //#endregion
101
+ //#region src/index.ts
102
+ const { createUnsupportedInline } = _canopycanopycanopy_b_ber_lib.utils;
16
103
  const MARKER_RE = /^(iframe)/;
17
104
  const DIRECTIVE_RE = /(iframe(?:-inline)?)(?::([^\s]+)(\s+.*)?)?$/;
18
- const render = ({
19
- instance,
20
- context
21
- }) => (tokens, index) => {
22
- var _context;
23
- const token = tokens[index];
24
- const marker = (0, _trim.default)(_context = token.info).call(_context).match(DIRECTIVE_RE);
25
- if (!marker) return '';
26
- const fileName = `_markdown/${context.fileName}.md`;
27
- const lineNumber = (0, _map.default)(token) ? (0, _map.default)(token)[0] : null;
28
- const type = marker[1];
29
- const args = (0, _helpers.prepare)({
30
- token,
31
- marker,
32
- context,
33
- instance,
34
- fileName,
35
- lineNumber
36
- });
37
- switch (type) {
38
- // Render the linked image and add the figure to state so that it's rendered
39
- // in the LOI
40
- case 'iframe':
41
- _State.default.add('figures', args);
42
- return (0, _helpers.createIframe)(args);
43
-
44
- // Render an inline iframe embed, or an unsupported message if not
45
- // running a reader or web build
46
- case 'iframe-inline':
47
- return (0, _helpers.supported)(_State.default.build) ? (0, _helpers.createIframeInline)(args) : (0, _utils.createUnsupportedInline)(args);
48
- default:
49
- throw new Error(`Something went wrong parsing [${args.type}] in [${context.fileName}]`);
50
- }
105
+ const render = ({ instance, context }) => (tokens, index) => {
106
+ const token = tokens[index];
107
+ const marker = token.info.trim().match(DIRECTIVE_RE);
108
+ if (!marker) return "";
109
+ const fileName = `_markdown/${context.fileName}.md`;
110
+ const lineNumber = token.map ? token.map[0] : null;
111
+ const type = marker[1];
112
+ const args = prepare({
113
+ token,
114
+ marker,
115
+ context,
116
+ instance,
117
+ fileName,
118
+ lineNumber
119
+ });
120
+ switch (type) {
121
+ case "iframe":
122
+ _canopycanopycanopy_b_ber_lib.State.add("figures", args);
123
+ return createIframe(args);
124
+ case "iframe-inline": return supported(_canopycanopycanopy_b_ber_lib.State.build) ? createIframeInline(args) : createUnsupportedInline(args);
125
+ default: throw new Error(`Something went wrong parsing [${args.type}] in [${context.fileName}]`);
126
+ }
127
+ };
128
+ var src_default = {
129
+ plugin: _canopycanopycanopy_b_ber_parser_figure.default,
130
+ name: "iframe",
131
+ renderer: ({ instance, context }) => ({
132
+ marker: _canopycanopycanopy_b_ber_shapes_directives.INLINE_DIRECTIVE_MARKER,
133
+ minMarkers: _canopycanopycanopy_b_ber_shapes_directives.INLINE_DIRECTIVE_MARKER_MIN_LENGTH,
134
+ validate: (params) => params.trim().match(MARKER_RE),
135
+ render: render({
136
+ instance,
137
+ context
138
+ })
139
+ })
51
140
  };
52
- var _default = exports.default = {
53
- plugin: _bBerParserFigure.default,
54
- name: 'iframe',
55
- renderer: ({
56
- instance,
57
- context
58
- }) => ({
59
- marker: _bBerShapesDirectives.INLINE_DIRECTIVE_MARKER,
60
- minMarkers: _bBerShapesDirectives.INLINE_DIRECTIVE_MARKER_MIN_LENGTH,
61
- validate: params => (0, _trim.default)(params).call(params).match(MARKER_RE),
62
- render: render({
63
- instance,
64
- context
65
- })
66
- })
67
- };
141
+ //#endregion
142
+ module.exports = src_default;
package/package.json CHANGED
@@ -1,14 +1,11 @@
1
1
  {
2
2
  "name": "@canopycanopycanopy/b-ber-grammar-iframe",
3
- "version": "3.0.8-nav-memo.4+d47a9aae",
3
+ "version": "3.0.8-next.100+20b74691",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "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",
7
+ "build": "tsdown",
8
+ "typecheck": "tsc --noEmit",
12
9
  "test": "jest"
13
10
  },
14
11
  "author": "Triple Canopy <b-ber@canopycanopycanopy.com> (https://triplecanopy.github.io/)",
@@ -17,19 +14,19 @@
17
14
  "access": "public"
18
15
  },
19
16
  "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"
17
+ "@swc/core": "^1.15.40",
18
+ "@swc/jest": "^0.2.39",
19
+ "jest": "^29.7.0",
20
+ "rimraf": "^2.7.1",
21
+ "tsdown": "^0.22.1",
22
+ "typescript": "^6.0.3"
26
23
  },
27
24
  "dependencies": {
28
- "@canopycanopycanopy/b-ber-grammar-attributes": "3.0.8-nav-memo.4+d47a9aae",
29
- "@canopycanopycanopy/b-ber-lib": "3.0.8-nav-memo.4+d47a9aae",
30
- "@canopycanopycanopy/b-ber-logger": "3.0.8-nav-memo.4+d47a9aae",
31
- "@canopycanopycanopy/b-ber-parser-figure": "3.0.8-nav-memo.4+d47a9aae",
32
- "@canopycanopycanopy/b-ber-shapes-directives": "3.0.8-nav-memo.4+d47a9aae",
25
+ "@canopycanopycanopy/b-ber-grammar-attributes": "3.0.8-next.100+20b74691",
26
+ "@canopycanopycanopy/b-ber-lib": "3.0.8-next.100+20b74691",
27
+ "@canopycanopycanopy/b-ber-logger": "3.0.8-next.100+20b74691",
28
+ "@canopycanopycanopy/b-ber-parser-figure": "3.0.8-next.100+20b74691",
29
+ "@canopycanopycanopy/b-ber-shapes-directives": "3.0.8-next.100+20b74691",
33
30
  "fs-extra": "^8.1.0",
34
31
  "lodash": "^4.17.21",
35
32
  "lodash.isundefined": "^3.0.1",
@@ -52,5 +49,6 @@
52
49
  "url": "https://maxwellsimmer.com"
53
50
  }
54
51
  ],
55
- "gitHead": "d47a9aae74dec3e3225e363b2434c7abe0fcf21b"
52
+ "gitHead": "20b746918e81513be00a2f04971b00b296850f61",
53
+ "types": "dist/index.d.ts"
56
54
  }
package/dist/helpers.js DELETED
@@ -1,125 +0,0 @@
1
- "use strict";
2
-
3
- var _Object$keys = require("@babel/runtime-corejs3/core-js-stable/object/keys");
4
- var _Object$getOwnPropertySymbols = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-symbols");
5
- var _filterInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/filter");
6
- var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
7
- var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
8
- var _Object$getOwnPropertyDescriptors = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptors");
9
- var _Object$defineProperties = require("@babel/runtime-corejs3/core-js-stable/object/define-properties");
10
- var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
11
- var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
12
- _Object$defineProperty(exports, "__esModule", {
13
- value: true
14
- });
15
- exports.createIframe = createIframe;
16
- exports.createIframeInline = createIframeInline;
17
- exports.prepare = prepare;
18
- exports.supported = supported;
19
- var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce"));
20
- var _entries = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/entries"));
21
- var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
22
- var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/objectWithoutProperties"));
23
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
24
- var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
25
- var _bBerLib = require("@canopycanopycanopy/b-ber-lib");
26
- var _utils = require("@canopycanopycanopy/b-ber-lib/utils");
27
- var _bBerGrammarAttributes = require("@canopycanopycanopy/b-ber-grammar-attributes");
28
- var _bBerShapesDirectives = require("@canopycanopycanopy/b-ber-shapes-directives");
29
- const _excluded = ["id", "commentStart", "commentEnd", "mediaType", "attrString", "source", "caption"];
30
- function ownKeys(e, r) { var t = _Object$keys(e); if (_Object$getOwnPropertySymbols) { var o = _Object$getOwnPropertySymbols(e); r && (o = _filterInstanceProperty(o).call(o, function (r) { return _Object$getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
31
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var _context2, _context3; var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? _forEachInstanceProperty(_context2 = ownKeys(Object(t), !0)).call(_context2, function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : _Object$getOwnPropertyDescriptors ? _Object$defineProperties(e, _Object$getOwnPropertyDescriptors(t)) : _forEachInstanceProperty(_context3 = ownKeys(Object(t))).call(_context3, function (r) { _Object$defineProperty(e, r, _Object$getOwnPropertyDescriptor(t, r)); }); } return e; }
32
- function supported(build) {
33
- return build === 'reader' || build === 'web';
34
- }
35
- function prepare({
36
- token,
37
- marker,
38
- context,
39
- instance,
40
- fileName,
41
- lineNumber
42
- }) {
43
- const [, type, id, attrs] = marker;
44
- const mediaType = (0, _utils.getMediaType)(type);
45
- const figureId = (0, _bBerGrammarAttributes.htmlId)(id);
46
- const page = `figure-${figureId}.xhtml`;
47
- const attrsObject = _objectSpread({
48
- source: '',
49
- height: 150,
50
- width: '100%',
51
- title: '',
52
- classes: '',
53
- poster: ''
54
- }, (0, _bBerGrammarAttributes.attributesObject)(attrs, type, {
55
- fileName,
56
- lineNumber
57
- }));
58
- (0, _utils.ensureSource)(attrsObject, type, fileName, lineNumber);
59
- (0, _utils.ensurePoster)(attrsObject, type);
60
- (0, _utils.ensureSupportedClassNames)(attrsObject, supported);
61
- return _objectSpread(_objectSpread({}, attrsObject), {}, {
62
- id: figureId,
63
- attrString: (0, _bBerGrammarAttributes.attributesString)(attrsObject, {
64
- classes: true
65
- }),
66
- commentStart: _bBerLib.Html.comment(`START: ${mediaType}:${type}#${figureId};`),
67
- commentEnd: _bBerLib.Html.comment(`END: ${mediaType}:${type}#${figureId};`),
68
- href: _State.default.build === 'reader' ? 'figures-titlepage.xhtml' : page,
69
- ref: context.fileName,
70
- caption: token.children ? instance.renderInline(token.children) : '',
71
- page,
72
- type,
73
- mediaType,
74
- mime: null,
75
- pageOrder: _State.default.figures.length,
76
- source: _bBerLib.Url.ensureDecoded(attrsObject.source),
77
- poster: attrsObject.poster
78
- });
79
- }
80
- function createIframe({
81
- id,
82
- href,
83
- poster
84
- }) {
85
- return `
86
- <div class="figure__small figure__small--landscape">
87
- <figure id="ref${id}">
88
- <a href="${href}#${id}">
89
- ${(0, _utils.renderPosterImage)(poster)}
90
- </a>
91
- </figure>
92
- </div>`;
93
- }
94
- function createIframeInline(data) {
95
- var _context;
96
- const {
97
- id,
98
- commentStart,
99
- commentEnd,
100
- mediaType,
101
- attrString: containerAttrsString,
102
- source,
103
- caption
104
- } = data,
105
- rest = (0, _objectWithoutProperties2.default)(data, _excluded);
106
- const defaults = {
107
- allow: 'fullscreen autoplay',
108
- frameborder: '0'
109
- };
110
- const iframeAttrs = (0, _reduce.default)(_context = (0, _entries.default)(_objectSpread(_objectSpread({}, defaults), rest))).call(_context, (acc, [key, val]) => {
111
- if (!_bBerShapesDirectives.htmlIframeAttributes.has(key) || val === '') return acc;
112
- return (0, _concat.default)(acc).call(acc, `${key}="${val}"`);
113
- }, []);
114
- const iframeAttrsString = iframeAttrs.join(' ');
115
- return `
116
- ${commentStart}
117
- <section class="${mediaType} figure__large figure__inline">
118
- <div id="${id}"${containerAttrsString}>
119
- <iframe src="${source}" ${iframeAttrsString}>
120
- </iframe>
121
- </div>
122
- ${(0, _utils.renderCaption)(caption, mediaType)}
123
- </section>
124
- ${commentEnd}`;
125
- }