@canopycanopycanopy/b-ber-grammar-media 2.0.0 → 3.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/dist/helpers.js CHANGED
@@ -1,27 +1,17 @@
1
1
  "use strict";
2
2
 
3
3
  var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
-
5
4
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
6
-
7
5
  _Object$defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
-
11
8
  exports.throwMissingIDError = exports.throMissingBuildTypeError = exports.createDirectiveString = exports.createAttributesString = void 0;
12
-
13
9
  var _trim = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/trim"));
14
-
15
10
  var _reduce = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/reduce"));
16
-
17
11
  var _entries = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/object/entries"));
18
-
19
12
  var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
20
-
21
13
  var _bBerLogger = _interopRequireDefault(require("@canopycanopycanopy/b-ber-logger"));
22
-
23
14
  var _bBerShapesDirectives = require("@canopycanopycanopy/b-ber-shapes-directives");
24
-
25
15
  const throMissingBuildTypeError = ({
26
16
  id,
27
17
  build
@@ -29,32 +19,23 @@ const throMissingBuildTypeError = ({
29
19
  let message = `Missing build type [${build}] in media.yml for the ID [${id}].`;
30
20
  message += ' ';
31
21
  message += 'Ensure that the media.yml file exists and contains the properties for each build type.';
32
-
33
22
  _bBerLogger.default.error(message);
34
23
  };
35
-
36
24
  exports.throMissingBuildTypeError = throMissingBuildTypeError;
37
-
38
25
  const throwMissingIDError = ({
39
26
  id
40
27
  }) => {
41
28
  let message = `Missing ID [${id}] in media.yml.`;
42
29
  message += ' ';
43
30
  message += 'Ensure that the media.yml file exists and contains the correct IDs.';
44
-
45
31
  _bBerLogger.default.error(message);
46
32
  };
47
-
48
33
  exports.throwMissingIDError = throwMissingIDError;
49
-
50
34
  const createAttributesString = data => {
51
35
  var _context, _context2;
52
-
53
36
  return (0, _trim.default)(_context = (0, _reduce.default)(_context2 = (0, _entries.default)(data)).call(_context2, (acc, [key, value]) => (0, _concat.default)(acc).call(acc, `${key}:"${value}" `), '')).call(_context);
54
37
  };
55
-
56
38
  exports.createAttributesString = createAttributesString;
57
-
58
39
  const createDirectiveString = ({
59
40
  type,
60
41
  modifier,
@@ -64,15 +45,12 @@ const createDirectiveString = ({
64
45
  }) => {
65
46
  const attributes = createAttributesString(rest);
66
47
  let directive = `${_bBerShapesDirectives.INLINE_DIRECTIVE_FENCE}${type}${modifier}:${id} ${attributes}`;
67
-
68
48
  if (caption) {
69
49
  directive += `\n${_bBerShapesDirectives.SECONDARY_INLINE_DIRECTIVE_FENCE_OPEN}`;
70
50
  directive += caption;
71
51
  directive += `\n${_bBerShapesDirectives.SECONDARY_INLINE_DIRECTIVE_FENCE_CLOSE}`;
72
52
  directive += '\n\n';
73
53
  }
74
-
75
54
  return directive;
76
55
  };
77
-
78
56
  exports.createDirectiveString = createDirectiveString;
package/dist/index.js CHANGED
@@ -1,30 +1,21 @@
1
1
  "use strict";
2
2
 
3
3
  var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
4
-
5
4
  var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
6
-
7
5
  _Object$defineProperty(exports, "__esModule", {
8
6
  value: true
9
7
  });
10
-
11
8
  exports.default = void 0;
12
-
13
9
  var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
14
-
15
10
  var _trim = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/trim"));
16
-
17
11
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/objectWithoutProperties"));
18
-
19
12
  var _State = _interopRequireDefault(require("@canopycanopycanopy/b-ber-lib/State"));
20
-
21
13
  var _bBerShapesDirectives = require("@canopycanopycanopy/b-ber-shapes-directives");
22
-
23
14
  var _helpers = require("./helpers");
24
-
25
15
  const _excluded = ["type", "caption"];
26
- const DIRECTIVE_REGEXP = /^media(?:-inline)?$/; // Render replacement Markdown string
16
+ const DIRECTIVE_REGEXP = /^media(?:-inline)?$/;
27
17
 
18
+ // Render replacement Markdown string
28
19
  function replace({
29
20
  type,
30
21
  id,
@@ -34,23 +25,26 @@ function replace({
34
25
  end
35
26
  }) {
36
27
  const _state$media$id$build = _State.default.media[id][build],
37
- {
38
- type: nextType,
39
- caption
40
- } = _state$media$id$build,
41
- rest = (0, _objectWithoutProperties2.default)(_state$media$id$build, _excluded); // Check if the replacement directive will be an inline directive based on
42
- // whether the original directive was `media` or `media-inline`
28
+ {
29
+ type: nextType,
30
+ caption
31
+ } = _state$media$id$build,
32
+ rest = (0, _objectWithoutProperties2.default)(_state$media$id$build, _excluded);
43
33
 
44
- const modifier = /-/.test(type) ? `-${type.split('-')[1]}` : ''; // Create replacement directive from media.yml
34
+ // Check if the replacement directive will be an inline directive based on
35
+ // whether the original directive was `media` or `media-inline`
36
+ const modifier = /-/.test(type) ? `-${type.split('-')[1]}` : '';
45
37
 
38
+ // Create replacement directive from media.yml
46
39
  const replacement = (0, _helpers.createDirectiveString)({
47
40
  type: nextType,
48
41
  id,
49
42
  modifier,
50
43
  caption,
51
44
  rest
52
- }); // Do replacement and update delta
45
+ });
53
46
 
47
+ // Do replacement and update delta
54
48
  const originalLength = end - begin;
55
49
  const replacementLength = replacement.length;
56
50
  const nextStr = `${(0, _slice.default)(str).call(str, 0, begin)}${replacement}${(0, _slice.default)(str).call(str, end)}`;
@@ -59,59 +53,58 @@ function replace({
59
53
  str: nextStr,
60
54
  delta: nextDelta
61
55
  };
62
- } // Parse the Markdown. Inject directives to replace the `media`/`media-inline`
63
- // directives. Returns an updated Markdown string
64
-
56
+ }
65
57
 
58
+ // Parse the Markdown. Inject directives to replace the `media`/`media-inline`
59
+ // directives. Returns an updated Markdown string
66
60
  function render(data) {
67
61
  let str = data;
68
62
  const {
69
63
  build
70
64
  } = _State.default;
71
- const lines = []; // TODO current fence in b-ber-shapes includes whitespace, should remove that.
72
- // Accounting for whitespace in `fenceLength` below
65
+ const lines = [];
73
66
 
67
+ // TODO current fence in b-ber-shapes includes whitespace, should remove that.
68
+ // Accounting for whitespace in `fenceLength` below
74
69
  const fenceLength = _bBerShapesDirectives.INLINE_DIRECTIVE_MARKER_MIN_LENGTH + 1;
75
-
76
70
  const fenceCharCode = _bBerShapesDirectives.INLINE_DIRECTIVE_MARKER.charCodeAt(0);
77
-
78
71
  const fence = _bBerShapesDirectives.INLINE_DIRECTIVE_FENCE;
79
- const newlineCharCode = 0x0a; // Create a map of the start/end indices of each line in the file.
72
+ const newlineCharCode = 0x0a;
80
73
 
74
+ // Create a map of the start/end indices of each line in the file.
81
75
  let lineStart = 0;
82
-
83
76
  for (let i = 0; i < str.length; i++) {
84
77
  if (str[i].charCodeAt(0) === newlineCharCode) {
85
78
  lines.push([lineStart, i]);
86
79
  lineStart = i + 1;
87
- } // Add markers in case there's only one line in the file with no trailing
88
- // newline
89
-
80
+ }
90
81
 
82
+ // Add markers in case there's only one line in the file with no trailing
83
+ // newline
91
84
  if (i === str.length - 1 && str.length && !lines.length) {
92
85
  lines.push([0, i + 1]);
93
86
  }
94
- } // Move through the file replacing entire lines if the match the `media` or
87
+ }
88
+
89
+ // Move through the file replacing entire lines if the match the `media` or
95
90
  // `media-inline` directive. Account for the change in line start/end
96
91
  // positions by storing a delta of the length of content added vs. removed
97
-
98
-
99
92
  let delta = 0;
100
-
101
93
  for (let i = 0; i < lines.length; i++) {
102
94
  var _context;
103
-
104
95
  let [begin, end] = lines[i];
105
96
  begin += delta;
106
- end += delta; // eslint-disable-next-line no-continue
107
-
108
- if (str.charCodeAt(begin) !== fenceCharCode) continue; // eslint-disable-next-line no-continue
97
+ end += delta;
109
98
 
99
+ // eslint-disable-next-line no-continue
100
+ if (str.charCodeAt(begin) !== fenceCharCode) continue;
101
+ // eslint-disable-next-line no-continue
110
102
  if ((0, _slice.default)(str).call(str, begin, begin + fenceLength) !== fence) continue;
111
103
  const directive = (0, _trim.default)(_context = (0, _slice.default)(str).call(str, begin + fenceLength, end)).call(_context);
112
- const [type, id] = directive.split(':'); // Check that the directive is a `media`/`media-inline` directive
113
- // eslint-disable-next-line no-continue
104
+ const [type, id] = directive.split(':');
114
105
 
106
+ // Check that the directive is a `media`/`media-inline` directive
107
+ // eslint-disable-next-line no-continue
115
108
  if (DIRECTIVE_REGEXP.test(type) !== true) continue;
116
109
  if (!_State.default.media[id]) (0, _helpers.throwMissingIDError)({
117
110
  id,
@@ -128,15 +121,14 @@ function render(data) {
128
121
  str,
129
122
  begin,
130
123
  end
131
- }); // eslint-disable-next-line prefer-destructuring
124
+ });
132
125
 
126
+ // eslint-disable-next-line prefer-destructuring
133
127
  str = nextDocumentData.str;
134
128
  delta += nextDocumentData.delta;
135
129
  }
136
-
137
130
  return str;
138
131
  }
139
-
140
132
  var _default = {
141
133
  render
142
134
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canopycanopycanopy/b-ber-grammar-media",
3
- "version": "2.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -26,9 +26,9 @@
26
26
  },
27
27
  "dependencies": {
28
28
  "@babel/runtime-corejs3": "^7.10.5",
29
- "@canopycanopycanopy/b-ber-lib": "2.0.0",
30
- "@canopycanopycanopy/b-ber-logger": "2.0.0",
31
- "@canopycanopycanopy/b-ber-shapes-directives": "2.0.0",
29
+ "@canopycanopycanopy/b-ber-lib": "3.0.2",
30
+ "@canopycanopycanopy/b-ber-logger": "3.0.2",
31
+ "@canopycanopycanopy/b-ber-shapes-directives": "3.0.2",
32
32
  "lodash": "^4.17.21",
33
33
  "tar": "^6.1.11"
34
34
  },
@@ -49,5 +49,5 @@
49
49
  "url": "https://maxwellsimmer.com"
50
50
  }
51
51
  ],
52
- "gitHead": "dbeae192709705f5bc211195ff343cbd999f9caf"
52
+ "gitHead": "1ec8ab9a4030fb59839d347beb04ab7605e3d5dd"
53
53
  }