rapier-markdown-kit 1.1.3 → 1.1.10

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 CHANGED
@@ -21,7 +21,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
21
  SOFTWARE.
22
22
 
23
23
  Files under this licence carry `SPDX-License-Identifier: MIT` in their first lines: the standard's
24
- grammar, marks and reference style (`spec/md-layout.mjs`, `spec/md-marks.mjs`, `spec/markdown-style.css`), the layout model and line planner
24
+ grammar, marks and reference style (`spec/md-layout.mjs`, `spec/md-marks.mjs`, `spec/flowchart.mjs`, `spec/markdown-style.css`), the layout model and line planner
25
25
  (`layout/model.mjs`, `layout/line-plan.mjs`), the Will grammar (`agent/will.mjs`), the picture appendix reader and writer
26
26
  (`spec/md-assets.mjs`), the two shared-page reference readers (`tools/read-shared-page.mjs`,
27
27
  `tools/read-shared-page.py`), and the host helper `packages/rapier-embed/embed.mjs`. The vendored Pretext (`agent/vendor/pretext`) and micromark carry their
package/README.md CHANGED
@@ -64,6 +64,7 @@ below belongs to the example, not to the package API.
64
64
  The example renders trusted Markdown, including its HTML. It demonstrates core Markdown, GFM tables,
65
65
  an aligned paragraph, a sized picture, a named text colour and a page break. Tasks,
66
66
  footnotes and other extensions use the caller's Markdown plugins; details use ordinary HTML.
67
+ In a Rapier page, supported Mermaid flowchart fences also draw offline in Rapier's look, so an agent can write a fence or use figures. The kit itself does not render diagrams.
67
68
  The complete markup contract, including callouts, diagrams, math and image wrapping, is
68
69
  [Reference style](https://github.com/jackskip22/rapier/blob/main/docs/markdown-standard.md#reference-style).
69
70
 
@@ -1,7 +1,8 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
 
3
3
  // `rotate`: degrees in (-180, 180], one decimal, omitted when 0; never written for a Rapier drawing (its turn lives in its SVG).
4
- export const fields = new Set(['align', 'width', 'wrap', 'x', 'y', 'rotate']);
4
+ // `opacity`: a picture's fade, a whole percent from 5 to 100, omitted at 100; the picture's bytes never change.
5
+ export const fields = new Set(['align', 'width', 'wrap', 'x', 'y', 'rotate', 'opacity']);
5
6
  export const alignments = new Set(['left', 'center', 'right', 'justify']);
6
7
  // `behind`/`front`: out of flow; the paragraph lays out as though the picture were absent.
7
8
  export const wraps = new Set(['around', 'box', 'behind', 'front']);
@@ -20,6 +21,7 @@ export function validLayout(value) {
20
21
  (!has(value, 'x') || percent(value.x) && (has(value, 'wrap') || has(value, 'width'))) &&
21
22
  (!has(value, 'y') || typeof value.y === 'number' && Number.isFinite(value.y) && value.y >= -50 && has(value, 'wrap')) &&
22
23
  (!has(value, 'rotate') || oneDecimalDegrees(value.rotate)) &&
24
+ (!has(value, 'opacity') || Number.isInteger(value.opacity) && value.opacity >= 5 && value.opacity <= 100) &&
23
25
  !(has(value, 'align') && (has(value, 'wrap') || has(value, 'x')));
24
26
  }
25
27
 
@@ -51,6 +53,9 @@ export function parseLayout(comment) {
51
53
  const magnitude = Number(number[2] + (number[3] ? '.' + number[3] : ''));
52
54
  if (number[1] && magnitude === 0) return null;
53
55
  value.rotate = number[1] ? -magnitude : magnitude;
56
+ } else if (key === 'opacity') {
57
+ if (!/^[1-9]\d{0,2}%$/.test(raw)) return null;
58
+ value.opacity = Number(raw.slice(0, -1));
54
59
  } else value[key] = raw;
55
60
  }
56
61
  return validLayout(value) ? value : null;
@@ -64,12 +69,18 @@ export function decodeLayoutAttribute(value) {
64
69
 
65
70
  export const parseLayoutAttribute = value => parseLayout(decodeLayoutAttribute(value));
66
71
 
72
+ // The picture's own CSS: its normal-flow width and x, and its fade.
67
73
  export function imageStyle(value) {
68
- if (!validLayout(value) || value.width == null) return '';
69
- const width = value.width;
70
- const left = value.x == null ? '' : ';display:block;margin-left:' +
71
- decimal(Number(Math.max(0, Math.min(100 - width, value.x - width / 2)).toFixed(6))) + '%;margin-right:0';
72
- return 'width:' + decimal(width) + '%;height:auto' + left;
74
+ if (!validLayout(value)) return '';
75
+ const parts = [];
76
+ if (value.width != null) {
77
+ const width = value.width;
78
+ const left = value.x == null ? '' : ';display:block;margin-left:' +
79
+ decimal(Number(Math.max(0, Math.min(100 - width, value.x - width / 2)).toFixed(6))) + '%;margin-right:0';
80
+ parts.push('width:' + decimal(width) + '%;height:auto' + left);
81
+ }
82
+ if (value.opacity != null && value.opacity < 100) parts.push('opacity:' + decimal(value.opacity / 100));
83
+ return parts.join(';');
73
84
  }
74
85
 
75
86
  // The one wrap-owner rule (layout/browser.js, layout/interchange.js, editor/share.js): prose after, else before, skipping pictures,
@@ -109,8 +120,9 @@ export function formatLayout(value) {
109
120
  if (!validLayout(value)) throw new TypeError('invalid_markdown_layout');
110
121
  const pairs = [];
111
122
  for (const key of fields) {
112
- if (has(value, key) && !(key === 'y' && value.y === 0) && !(key === 'rotate' && value.rotate === 0)) pairs.push(key + '=' +
113
- (key === 'width' || key === 'x' ? decimal(value[key]) + '%' : key === 'y' ? decimal(value.y) + 'em' :
123
+ if (has(value, key) && !(key === 'y' && value.y === 0) && !(key === 'rotate' && value.rotate === 0) &&
124
+ !(key === 'opacity' && value.opacity === 100)) pairs.push(key + '=' +
125
+ (key === 'width' || key === 'x' || key === 'opacity' ? decimal(value[key]) + '%' : key === 'y' ? decimal(value.y) + 'em' :
114
126
  key === 'rotate' ? decimal(value.rotate) + 'deg' : value[key]));
115
127
  }
116
128
  return pairs.length ? '<!--md-layout:v1 ' + pairs.join(' ') + '-->' : '';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rapier-markdown-kit",
3
- "version": "1.1.3",
3
+ "version": "1.1.10",
4
4
  "description": "Read, write and style Self-contained Markdown: the universal stylesheet, picture layout, text marks, picture appendix, line planner and Will/1 markers. MIT, no dependencies.",
5
5
  "author": "Jack Skipworth",
6
6
  "license": "MIT",
package/style.css CHANGED
@@ -49,6 +49,7 @@
49
49
  --md-color-dark:var(--md-color);
50
50
  --md-highlight-color:var(--md-color-accent);
51
51
  --md-image-width:100%;
52
+ --md-drawing-width:0px;
52
53
  --md-task-box:clamp(14px,.92em,24px);
53
54
  --md-jump-gap:.9rem;
54
55
  --md-jump-marker-inline-start:-1.18rem;
@@ -158,6 +159,7 @@
158
159
  The same class reaches rendered blocks and source previews: the owner
159
160
  marks each admitted drawing `rapier-diagram`, which remains stable when export namespaces
160
161
  local SVG IDs and references. */
162
+ :where(.md-render) svg.rapier-native-flowchart{display:block;margin-inline:auto;height:auto}
161
163
  :where(.md-render) svg.rapier-diagram{
162
164
  display:block;margin-inline:auto;height:auto;
163
165
  font-family:var(--md-font-sans)!important;
@@ -330,10 +332,12 @@
330
332
  :where(.md-render) svg.rapier-diagram .grid path{stroke:none!important}
331
333
  :where(.md-render) svg.rapier-diagram .grid .tick text{fill:var(--md-diagram-quiet)!important;font-size:var(--md-text-xs)!important}
332
334
  :where(.md-render) svg.rapier-diagram .today{stroke:var(--md-diagram-c6)!important}
333
- /* Paper cannot be scrolled sideways, so on paper a diagram goes back to fitting the page. */
335
+ /* Paper cannot be scrolled sideways, so on paper a diagram, and a wide drawing, go back to fitting the page. */
334
336
  @media print{
335
337
  :where(.md-render) .diagram-block{overflow:visible!important}
336
- :where(.md-render) svg.rapier-diagram{width:auto!important;max-width:100%!important}
338
+ :where(.md-render) svg.rapier-diagram,:where(.md-render) svg.rapier-native-flowchart{width:auto!important;max-width:100%!important}
339
+ .md-render img[data-md-drawing]{min-width:0!important}
340
+ .md-render :has(>img[data-md-drawing],>a>img[data-md-drawing]){overflow:visible!important}
337
341
  }
338
342
  :where(.md-render) .diagram-reason {
339
343
  margin: .4em 0 0;
@@ -702,6 +706,12 @@
702
706
  vertical-align:middle;
703
707
  }
704
708
  .md-render img[data-rapier-image-size]{width:min(var(--md-image-width),100%);height:auto}
709
+ /* A drawing (an SVG picture, as every Draw drawing is) shown at its own size carries that size, and shrinks to the column only
710
+ while its words stay legible: at 12/14 of it, Draw's default words (14 px) are 12 px, the smallest text a phone reads
711
+ (measured on a 390 px phone, the lane drawing-dark-wide). There it stops, and its block scrolls sideways, as a wide diagram
712
+ does; a drawing that fits, or shrinks less than that, is drawn as it always was. */
713
+ .md-render img[data-md-drawing]{min-width:calc(var(--md-drawing-width) * 12 / 14)}
714
+ .md-render :has(>img[data-md-drawing],>a>img[data-md-drawing]){overflow-x:auto}
705
715
  .md-render img:is([data-rapier-asset],[data-rapier-image-url]):not([data-rapier-asset-state="ready"]){background:color-mix(in srgb,var(--md-color-text) 5%,transparent)}
706
716
 
707
717
  .md-render dl{margin:0 0 var(--md-space-4)}