@diplodoc/transform 4.70.4 → 4.72.0
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/css/_yfm-only.css +4 -4
- package/dist/css/_yfm-only.css.map +3 -3
- package/dist/css/_yfm-only.min.css +1 -1
- package/dist/css/_yfm-only.min.css.map +3 -3
- package/dist/css/base.css.map +1 -1
- package/dist/css/base.min.css.map +1 -1
- package/dist/css/print.css.map +1 -1
- package/dist/css/yfm.css +4 -4
- package/dist/css/yfm.css.map +3 -3
- package/dist/css/yfm.min.css +1 -1
- package/dist/css/yfm.min.css.map +3 -3
- package/dist/js/base.js +396 -215
- package/dist/js/base.js.map +4 -4
- package/dist/js/base.min.js +1 -6
- package/dist/js/base.min.js.map +4 -4
- package/dist/js/yfm.js +429 -228
- package/dist/js/yfm.js.map +4 -4
- package/dist/js/yfm.min.js +1 -6
- package/dist/js/yfm.min.js.map +4 -4
- package/dist/scss/{_inline-code.scss → _tooltip.scss} +1 -1
- package/dist/scss/_yfm-only.scss +1 -1
- package/lib/plugins/anchors/index.js +1 -1
- package/lib/plugins/anchors/index.js.map +1 -1
- package/lib/plugins/images/index.js +7 -0
- package/lib/plugins/images/index.js.map +1 -1
- package/lib/plugins/term/termDefinitions.js +54 -27
- package/lib/plugins/term/termDefinitions.js.map +1 -1
- package/lib/typings.d.ts +10 -0
- package/package.json +2 -2
- package/src/js/anchor.ts +27 -3
- package/src/js/{inline-code/constant.ts → constant.ts} +1 -9
- package/src/js/inline-code/index.ts +24 -42
- package/src/js/tooltip/constant.ts +25 -0
- package/src/js/tooltip/index.ts +2 -0
- package/src/js/tooltip/tooltip.ts +263 -0
- package/src/js/tooltip/types.ts +59 -0
- package/src/js/tooltip/utils.ts +247 -0
- package/src/scss/{_inline-code.scss → _tooltip.scss} +1 -1
- package/src/scss/_yfm-only.scss +1 -1
- package/src/transform/plugins/anchors/index.ts +1 -1
- package/src/transform/plugins/images/index.ts +8 -0
- package/src/transform/plugins/term/termDefinitions.ts +71 -33
- package/src/transform/typings.ts +10 -0
- package/src/js/inline-code/utils.ts +0 -217
|
@@ -1,217 +0,0 @@
|
|
|
1
|
-
import type {Lang} from 'src/transform/typings';
|
|
2
|
-
|
|
3
|
-
import {getCoords} from '../term/utils';
|
|
4
|
-
|
|
5
|
-
import {INLINE_CODE, INLINE_CODE_CLASS, INLINE_CODE_ID, LANG_TOKEN, OPEN_CLASS} from './constant';
|
|
6
|
-
|
|
7
|
-
export let timer: ReturnType<typeof setTimeout> | null = null;
|
|
8
|
-
|
|
9
|
-
let isListenerNeeded = true;
|
|
10
|
-
|
|
11
|
-
export function getTooltipElement(): HTMLElement | null {
|
|
12
|
-
return document.getElementById(INLINE_CODE_ID);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
function setTooltipAriaAttributes(tooltipElement: HTMLElement, targetElement: HTMLElement): void {
|
|
16
|
-
const ariaLive = targetElement.getAttribute('aria-live') || 'polite';
|
|
17
|
-
tooltipElement?.setAttribute('aria-live', ariaLive);
|
|
18
|
-
tooltipElement?.setAttribute('aria-modal', 'true');
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function checkTimerAndClear() {
|
|
22
|
-
if (timer) {
|
|
23
|
-
clearTimeout(timer);
|
|
24
|
-
timer = null;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
function tooltipParentElement(target: HTMLElement | null) {
|
|
29
|
-
if (!target) {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const closestScrollableParent = target.closest('table') || target.closest('code');
|
|
34
|
-
|
|
35
|
-
return closestScrollableParent || target.parentElement;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function tooltipOnResize() {
|
|
39
|
-
const openedDefinition = getTooltipElement();
|
|
40
|
-
|
|
41
|
-
if (!openedDefinition) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const inlineId = openedDefinition.getAttribute('inline-id') || '';
|
|
45
|
-
const targetElement = document.getElementById(inlineId);
|
|
46
|
-
|
|
47
|
-
if (!targetElement) {
|
|
48
|
-
return;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
setTooltipPosition(openedDefinition, targetElement);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
export function setTooltipPosition(tooltipElement: HTMLElement, targetElement: HTMLElement): void {
|
|
55
|
-
const {
|
|
56
|
-
x: inlineX,
|
|
57
|
-
y: inlineY,
|
|
58
|
-
right: inlineRight,
|
|
59
|
-
left: inlineLeft,
|
|
60
|
-
width: inlineWidth,
|
|
61
|
-
height: inlineHeight,
|
|
62
|
-
} = targetElement.getBoundingClientRect();
|
|
63
|
-
|
|
64
|
-
const tooltipParent = tooltipParentElement(targetElement);
|
|
65
|
-
|
|
66
|
-
if (!tooltipParent) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const {right: tooltipParentRight, left: tooltipParentLeft} =
|
|
71
|
-
tooltipParent.getBoundingClientRect();
|
|
72
|
-
|
|
73
|
-
if ((tooltipParentRight < inlineLeft || tooltipParentLeft > inlineRight) && !isListenerNeeded) {
|
|
74
|
-
closeTooltip(tooltipElement);
|
|
75
|
-
return;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (isListenerNeeded && tooltipParent) {
|
|
79
|
-
tooltipParent.addEventListener('scroll', tooltipOnResize);
|
|
80
|
-
isListenerNeeded = false;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const relativeX = Number(tooltipElement.getAttribute('relativeX'));
|
|
84
|
-
const relativeY = Number(tooltipElement.getAttribute('relativeY'));
|
|
85
|
-
|
|
86
|
-
if (relativeX === inlineX && relativeY === inlineY) {
|
|
87
|
-
return;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
tooltipElement.setAttribute('relativeX', String(inlineX));
|
|
91
|
-
tooltipElement.setAttribute('relativeY', String(inlineY));
|
|
92
|
-
|
|
93
|
-
const offsetTop = inlineHeight + 5;
|
|
94
|
-
const definitionParent = tooltipElement.parentElement;
|
|
95
|
-
|
|
96
|
-
if (!definitionParent) {
|
|
97
|
-
return;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
const {width: definitionWidth} = tooltipElement.getBoundingClientRect();
|
|
101
|
-
const {left: definitionParentLeft} = definitionParent.getBoundingClientRect();
|
|
102
|
-
|
|
103
|
-
// If definition not fit document change base alignment
|
|
104
|
-
const definitionLeftCoordinate = Number(getCoords(targetElement).left);
|
|
105
|
-
const definitionRightCoordinate = definitionWidth + definitionLeftCoordinate;
|
|
106
|
-
|
|
107
|
-
const definitionOutOfScreenOnLeft = definitionLeftCoordinate - definitionWidth < 0;
|
|
108
|
-
const definitionOutOfScreenOnRight = definitionRightCoordinate > document.body.clientWidth;
|
|
109
|
-
|
|
110
|
-
const isAlignSwapped = definitionOutOfScreenOnRight || document.dir === 'rtl';
|
|
111
|
-
const fitDefinitionDocument =
|
|
112
|
-
isAlignSwapped && !definitionOutOfScreenOnLeft ? definitionWidth - inlineWidth : 0;
|
|
113
|
-
const customHeaderTop = getCoords(definitionParent).top - definitionParent.offsetTop;
|
|
114
|
-
const offsetRight = 5;
|
|
115
|
-
const shiftLeft = definitionOutOfScreenOnRight
|
|
116
|
-
? definitionRightCoordinate - document.body.clientWidth + offsetRight
|
|
117
|
-
: 0;
|
|
118
|
-
const offsetLeft =
|
|
119
|
-
getCoords(targetElement).left -
|
|
120
|
-
definitionParentLeft +
|
|
121
|
-
definitionParent.offsetLeft -
|
|
122
|
-
fitDefinitionDocument;
|
|
123
|
-
|
|
124
|
-
const isShiftLeftNeeded = offsetLeft + definitionWidth >= document.body.clientWidth;
|
|
125
|
-
|
|
126
|
-
tooltipElement.style.top =
|
|
127
|
-
Number(getCoords(targetElement).top + offsetTop - customHeaderTop) + 'px';
|
|
128
|
-
tooltipElement.style.left = Number(offsetLeft - (isShiftLeftNeeded ? shiftLeft : 0)) + 'px';
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
export function getInlineCodeByTooltip(definition: HTMLElement) {
|
|
132
|
-
const inlineId = definition.getAttribute('inline-id');
|
|
133
|
-
|
|
134
|
-
return inlineId ? document.getElementById(inlineId) : null;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function closeTooltipFn(definition: HTMLElement) {
|
|
138
|
-
definition.classList.remove(OPEN_CLASS);
|
|
139
|
-
const inline = getInlineCodeByTooltip(definition);
|
|
140
|
-
const inlineCodepParent = tooltipParentElement(inline);
|
|
141
|
-
const tooltipParent = tooltipParentElement(definition);
|
|
142
|
-
|
|
143
|
-
definition.removeAttribute('inline-id');
|
|
144
|
-
|
|
145
|
-
if (!inlineCodepParent || !tooltipParent) {
|
|
146
|
-
return;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
tooltipParent.removeChild(definition);
|
|
150
|
-
inlineCodepParent.removeEventListener('scroll', tooltipOnResize);
|
|
151
|
-
isListenerNeeded = true;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
function createTooltip() {
|
|
155
|
-
let tooltip = getTooltipElement();
|
|
156
|
-
|
|
157
|
-
if (!tooltip) {
|
|
158
|
-
const pageContent = document.querySelector('.dc-doc-page__content') || document.body;
|
|
159
|
-
const lang = document.documentElement.lang || 'en';
|
|
160
|
-
const tooltipText = LANG_TOKEN[lang as Lang] ?? LANG_TOKEN.en;
|
|
161
|
-
const host = document.createElement('div');
|
|
162
|
-
|
|
163
|
-
host.innerHTML = `
|
|
164
|
-
<div id="${INLINE_CODE_ID}" class="${INLINE_CODE_CLASS}"
|
|
165
|
-
role="dialog" aria-live="polite" aria-modal="true">
|
|
166
|
-
${tooltipText}
|
|
167
|
-
</div>
|
|
168
|
-
`;
|
|
169
|
-
|
|
170
|
-
tooltip = host.firstElementChild as HTMLElement;
|
|
171
|
-
pageContent.appendChild(tooltip);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
return tooltip;
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
export function openTooltip(target: HTMLElement) {
|
|
178
|
-
const tooltip = createTooltip();
|
|
179
|
-
|
|
180
|
-
if (!target.matches(INLINE_CODE) || !tooltip) {
|
|
181
|
-
return;
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
tooltip.setAttribute('inline-id', target.getAttribute('id') || '');
|
|
185
|
-
setTooltipAriaAttributes(tooltip, target);
|
|
186
|
-
setTooltipPosition(tooltip, target);
|
|
187
|
-
|
|
188
|
-
// In order not to get rid of the smooth appearance effect, I had to do this
|
|
189
|
-
if (tooltip.classList.contains(OPEN_CLASS)) {
|
|
190
|
-
tooltip.classList.remove(OPEN_CLASS);
|
|
191
|
-
requestAnimationFrame(() => {
|
|
192
|
-
tooltip.classList.add(OPEN_CLASS);
|
|
193
|
-
});
|
|
194
|
-
} else {
|
|
195
|
-
tooltip.classList.add(OPEN_CLASS);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return tooltip;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export function closeTooltip(target: HTMLElement) {
|
|
202
|
-
checkTimerAndClear();
|
|
203
|
-
closeTooltipFn(target);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
export function tooltipWorker(target: HTMLElement) {
|
|
207
|
-
const definition = openTooltip(target);
|
|
208
|
-
|
|
209
|
-
if (!definition) {
|
|
210
|
-
return;
|
|
211
|
-
}
|
|
212
|
-
checkTimerAndClear();
|
|
213
|
-
timer = setTimeout(() => {
|
|
214
|
-
closeTooltip(definition);
|
|
215
|
-
timer = null;
|
|
216
|
-
}, 1000);
|
|
217
|
-
}
|