rapier-markdown-kit 1.1.3 → 1.1.4
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/spec/md-layout.mjs +20 -8
- package/package.json +1 -1
- package/style.css +10 -1
package/dist/spec/md-layout.mjs
CHANGED
|
@@ -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
|
-
|
|
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)
|
|
69
|
-
const
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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)
|
|
113
|
-
(key === '
|
|
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
|
+
"version": "1.1.4",
|
|
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;
|
|
@@ -330,10 +331,12 @@
|
|
|
330
331
|
:where(.md-render) svg.rapier-diagram .grid path{stroke:none!important}
|
|
331
332
|
:where(.md-render) svg.rapier-diagram .grid .tick text{fill:var(--md-diagram-quiet)!important;font-size:var(--md-text-xs)!important}
|
|
332
333
|
:where(.md-render) svg.rapier-diagram .today{stroke:var(--md-diagram-c6)!important}
|
|
333
|
-
/* Paper cannot be scrolled sideways, so on paper a diagram
|
|
334
|
+
/* Paper cannot be scrolled sideways, so on paper a diagram, and a wide drawing, go back to fitting the page. */
|
|
334
335
|
@media print{
|
|
335
336
|
:where(.md-render) .diagram-block{overflow:visible!important}
|
|
336
337
|
:where(.md-render) svg.rapier-diagram{width:auto!important;max-width:100%!important}
|
|
338
|
+
.md-render img[data-md-drawing]{min-width:0!important}
|
|
339
|
+
.md-render :has(>img[data-md-drawing],>a>img[data-md-drawing]){overflow:visible!important}
|
|
337
340
|
}
|
|
338
341
|
:where(.md-render) .diagram-reason {
|
|
339
342
|
margin: .4em 0 0;
|
|
@@ -702,6 +705,12 @@
|
|
|
702
705
|
vertical-align:middle;
|
|
703
706
|
}
|
|
704
707
|
.md-render img[data-rapier-image-size]{width:min(var(--md-image-width),100%);height:auto}
|
|
708
|
+
/* A drawing (an SVG picture, as every Draw drawing is) shown at its own size carries that size, and shrinks to the column only
|
|
709
|
+
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
|
|
710
|
+
(measured on a 390 px phone, the lane drawing-dark-wide). There it stops, and its block scrolls sideways, as a wide diagram
|
|
711
|
+
does; a drawing that fits, or shrinks less than that, is drawn as it always was. */
|
|
712
|
+
.md-render img[data-md-drawing]{min-width:calc(var(--md-drawing-width) * 12 / 14)}
|
|
713
|
+
.md-render :has(>img[data-md-drawing],>a>img[data-md-drawing]){overflow-x:auto}
|
|
705
714
|
.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
715
|
|
|
707
716
|
.md-render dl{margin:0 0 var(--md-space-4)}
|