@diplodoc/transform 4.70.3 → 4.71.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.
Files changed (42) hide show
  1. package/dist/css/_yfm-only.css +4 -4
  2. package/dist/css/_yfm-only.css.map +3 -3
  3. package/dist/css/_yfm-only.min.css +1 -1
  4. package/dist/css/_yfm-only.min.css.map +3 -3
  5. package/dist/css/base.css +1 -0
  6. package/dist/css/base.css.map +3 -3
  7. package/dist/css/base.min.css +1 -1
  8. package/dist/css/base.min.css.map +3 -3
  9. package/dist/css/print.css.map +1 -1
  10. package/dist/css/yfm.css +6 -4
  11. package/dist/css/yfm.css.map +3 -3
  12. package/dist/css/yfm.min.css +1 -1
  13. package/dist/css/yfm.min.css.map +3 -3
  14. package/dist/js/base.js +396 -215
  15. package/dist/js/base.js.map +4 -4
  16. package/dist/js/base.min.js +1 -6
  17. package/dist/js/base.min.js.map +4 -4
  18. package/dist/js/yfm.js +429 -228
  19. package/dist/js/yfm.js.map +4 -4
  20. package/dist/js/yfm.min.js +1 -6
  21. package/dist/js/yfm.min.js.map +4 -4
  22. package/dist/scss/_common.scss +1 -0
  23. package/dist/scss/_modal.scss +1 -0
  24. package/dist/scss/{_inline-code.scss → _tooltip.scss} +1 -1
  25. package/dist/scss/_yfm-only.scss +1 -1
  26. package/lib/plugins/anchors/index.js +1 -1
  27. package/lib/plugins/anchors/index.js.map +1 -1
  28. package/package.json +1 -1
  29. package/src/js/anchor.ts +27 -3
  30. package/src/js/{inline-code/constant.ts → constant.ts} +1 -9
  31. package/src/js/inline-code/index.ts +24 -42
  32. package/src/js/tooltip/constant.ts +25 -0
  33. package/src/js/tooltip/index.ts +2 -0
  34. package/src/js/tooltip/tooltip.ts +263 -0
  35. package/src/js/tooltip/types.ts +59 -0
  36. package/src/js/tooltip/utils.ts +247 -0
  37. package/src/scss/_common.scss +1 -0
  38. package/src/scss/_modal.scss +1 -0
  39. package/src/scss/{_inline-code.scss → _tooltip.scss} +1 -1
  40. package/src/scss/_yfm-only.scss +1 -1
  41. package/src/transform/plugins/anchors/index.ts +1 -1
  42. package/src/js/inline-code/utils.ts +0 -217
package/dist/js/base.js CHANGED
@@ -157,26 +157,365 @@
157
157
  });
158
158
  }
159
159
 
160
- // src/js/anchor.ts
161
- var ANCHOR_BUTTON_SELECTOR = ".yfm-clipboard-anchor";
162
- if (typeof document !== "undefined") {
163
- document.addEventListener("click", (event) => {
164
- const target = getEventTarget(event);
165
- if (isCustom(event) || !target.matches(ANCHOR_BUTTON_SELECTOR)) {
166
- return;
160
+ // src/js/tooltip/constant.ts
161
+ var PAGE_CONTAINER_SELECTOR = ".dc-doc-page__content";
162
+ var TOOLTIP_BASE_CLASS = "yfm yfm-tooltip";
163
+ var TOOLTIP_OPEN_CLASS = "open";
164
+ var TOOLTIP_DATA_ATTR = "data-tooltip-id";
165
+ var DEFAULT_OFFSET_VALUES = { mainAxis: 5 };
166
+ var OPPOSITE_SIDES = {
167
+ top: "bottom",
168
+ bottom: "top",
169
+ left: "right",
170
+ right: "left"
171
+ };
172
+ var DEFAULT_SIDE_OBJECT = {
173
+ top: 0,
174
+ bottom: 0,
175
+ left: 0,
176
+ right: 0
177
+ };
178
+
179
+ // src/js/tooltip/utils.ts
180
+ function isVerticalSide(side) {
181
+ return side === "top" || side === "bottom";
182
+ }
183
+ function createSideObject(value = 0) {
184
+ if (typeof value === "number") {
185
+ return { top: value, bottom: value, left: value, right: value };
186
+ }
187
+ return { ...DEFAULT_SIDE_OBJECT, ...value };
188
+ }
189
+ function parsePlacement(placement) {
190
+ const [side, alignment] = placement.split("-");
191
+ return { side, alignment };
192
+ }
193
+ function getOppositeSide(side) {
194
+ return OPPOSITE_SIDES[side];
195
+ }
196
+ function flipPlacement(placement) {
197
+ const { side, alignment } = parsePlacement(placement);
198
+ const opposite = getOppositeSide(side);
199
+ return alignment ? `${opposite}-${alignment}` : opposite;
200
+ }
201
+ function getOverflow(tooltip3, coords, viewport) {
202
+ const rect = updateRect(tooltip3, { top: coords.y, left: coords.x });
203
+ return detectOverflow(viewport, rect, 5);
204
+ }
205
+ function shouldFlip(overflow, flippedOverflow, side) {
206
+ const opposite = getOppositeSide(side);
207
+ return overflow[side] > 0 && flippedOverflow[opposite] < overflow[side];
208
+ }
209
+ function computePosition(reference, tooltip3, viewport, placement, offset, isRtl, flip = true) {
210
+ const coords = computeCoordsFromPlacement(reference, tooltip3, offset, placement, isRtl);
211
+ if (!flip) {
212
+ return { coords, placement };
213
+ }
214
+ const overflow = getOverflow(tooltip3, coords, viewport);
215
+ const { side } = parsePlacement(placement);
216
+ if (overflow[side] <= 0) {
217
+ return { coords, placement };
218
+ }
219
+ const flipped = flipPlacement(placement);
220
+ const flippedCoords = computeCoordsFromPlacement(reference, tooltip3, offset, flipped, isRtl);
221
+ const flippedOverflow = getOverflow(tooltip3, flippedCoords, viewport);
222
+ if (shouldFlip(overflow, flippedOverflow, side)) {
223
+ return { coords: flippedCoords, placement: flipped };
224
+ }
225
+ return { coords, placement };
226
+ }
227
+ function generateId() {
228
+ const random = Math.random().toString(36).substring(2, 6);
229
+ const now = Date.now().toString(36);
230
+ return `${random}${now}`;
231
+ }
232
+ function createRect(params) {
233
+ return {
234
+ ...params,
235
+ right: params.left + params.width,
236
+ bottom: params.top + params.height
237
+ };
238
+ }
239
+ function updateRect(rect, params) {
240
+ var _a, _b, _c, _d;
241
+ return createRect({
242
+ top: (_a = params.top) != null ? _a : rect.top,
243
+ left: (_b = params.left) != null ? _b : rect.left,
244
+ width: (_c = params.width) != null ? _c : rect.width,
245
+ height: (_d = params.height) != null ? _d : rect.height
246
+ });
247
+ }
248
+ function getViewportRect() {
249
+ const { documentElement, body } = document;
250
+ const scrollTop = window.scrollY || documentElement.scrollTop || body.scrollTop;
251
+ const scrollLeft = window.scrollX || documentElement.scrollLeft || body.scrollLeft;
252
+ const clientTop = documentElement.clientTop || body.clientTop || 0;
253
+ const clientLeft = documentElement.clientLeft || body.clientLeft || 0;
254
+ return createRect({
255
+ top: Math.round(scrollTop - clientTop),
256
+ left: Math.round(scrollLeft - clientLeft),
257
+ width: document.body.clientWidth,
258
+ height: document.body.clientHeight
259
+ });
260
+ }
261
+ function getElementRect(element) {
262
+ const viewport = getViewportRect();
263
+ const box = element.getBoundingClientRect();
264
+ return createRect({
265
+ top: Math.round(box.top + viewport.top),
266
+ left: Math.round(box.left + viewport.left),
267
+ width: box.width,
268
+ height: box.height
269
+ });
270
+ }
271
+ function computeAxisOffset(offset, side, isRtl) {
272
+ const { mainAxis = 0, crossAxis = 0 } = offset;
273
+ const isVertical = isVerticalSide(side);
274
+ const mainDirection = side === "top" || side === "left" ? -1 : 1;
275
+ const crossDirection = isRtl && isVertical ? -1 : 1;
276
+ const mainOffset = mainAxis * mainDirection;
277
+ const crossOffset = crossAxis * crossDirection;
278
+ if (isVertical) {
279
+ return { x: crossOffset, y: mainOffset };
280
+ }
281
+ return { x: mainOffset, y: crossOffset };
282
+ }
283
+ function computeCoordsFromPlacement(reference, tooltip3, offset, placement, isRtl) {
284
+ const { side, alignment } = parsePlacement(placement);
285
+ const isVertical = isVerticalSide(side);
286
+ const alignmentAxis = isVertical ? "x" : "y";
287
+ const alignLength = alignmentAxis === "y" ? "height" : "width";
288
+ const centerX = reference.left + reference.width / 2 - tooltip3.width / 2;
289
+ const centerY = reference.top + reference.height / 2 - tooltip3.height / 2;
290
+ const alignmentOffset = reference[alignLength] / 2 - tooltip3[alignLength] / 2;
291
+ const coords = { x: reference.left, y: reference.top };
292
+ switch (side) {
293
+ case "top": {
294
+ coords.x = centerX;
295
+ coords.y = reference.top - tooltip3.height;
296
+ break;
167
297
  }
168
- const href = target.getAttribute("data-href") || "";
169
- const link = new URL(href, window.location.href).toString();
170
- copyToClipboard(link);
298
+ case "bottom": {
299
+ coords.x = centerX;
300
+ coords.y = reference.top + reference.height;
301
+ break;
302
+ }
303
+ case "right": {
304
+ coords.x = reference.left + reference.width;
305
+ coords.y = centerY;
306
+ break;
307
+ }
308
+ case "left": {
309
+ coords.x = reference.left - tooltip3.width;
310
+ coords.y = centerY;
311
+ break;
312
+ }
313
+ }
314
+ switch (alignment) {
315
+ case "start": {
316
+ coords[alignmentAxis] -= alignmentOffset * (isRtl && isVertical ? -1 : 1);
317
+ break;
318
+ }
319
+ case "end": {
320
+ coords[alignmentAxis] += alignmentOffset * (isRtl && isVertical ? -1 : 1);
321
+ break;
322
+ }
323
+ }
324
+ const axisOffset = computeAxisOffset(offset, side, isRtl);
325
+ coords.x += axisOffset.x;
326
+ coords.y += axisOffset.y;
327
+ return coords;
328
+ }
329
+ function convertToRelativeToOffsetParentRect(rect, offsetParent) {
330
+ const offsetRect = getElementRect(offsetParent);
331
+ return createRect({
332
+ top: rect.top - offsetRect.top + offsetParent.offsetTop,
333
+ left: rect.left - offsetRect.left + offsetParent.offsetLeft,
334
+ width: rect.width,
335
+ height: rect.height
171
336
  });
172
337
  }
338
+ function detectOverflow(boundary, element, padding = 0) {
339
+ const { top, bottom, left, right } = createSideObject(padding);
340
+ return {
341
+ top: boundary.top - element.top + top,
342
+ bottom: element.bottom - boundary.bottom + bottom,
343
+ left: boundary.left - element.left + left,
344
+ right: element.right - boundary.right + right
345
+ };
346
+ }
347
+
348
+ // src/js/tooltip/tooltip.ts
349
+ function createTooltipFactory(options = {}) {
350
+ const { closeDelay = 1e3, additionalClassName } = options;
351
+ let initialized = false;
352
+ const state = {
353
+ currentId: null,
354
+ timer: null,
355
+ unsubscribe: null
356
+ };
357
+ const getActiveTooltip = () => {
358
+ if (!state.currentId) {
359
+ return null;
360
+ }
361
+ return document.getElementById(state.currentId);
362
+ };
363
+ const getActiveReference = () => {
364
+ if (!state.currentId) {
365
+ return null;
366
+ }
367
+ return getReferenceByTooltipId(state.currentId);
368
+ };
369
+ const hide = () => {
370
+ const tooltip3 = getActiveTooltip();
371
+ if (state.timer) {
372
+ clearTimeout(state.timer);
373
+ state.timer = null;
374
+ }
375
+ if (state.unsubscribe) {
376
+ state.unsubscribe();
377
+ state.unsubscribe = null;
378
+ }
379
+ if (tooltip3) {
380
+ tooltip3.classList.remove(TOOLTIP_OPEN_CLASS);
381
+ detachTooltip(tooltip3);
382
+ state.currentId = null;
383
+ }
384
+ };
385
+ const show = (reference, text) => {
386
+ hide();
387
+ const tooltip3 = createTooltipElement({ text, className: additionalClassName });
388
+ const update = updateTooltipPosition.bind(null, options, reference, tooltip3);
389
+ state.currentId = tooltip3.id;
390
+ attachTooltip(tooltip3, reference);
391
+ state.unsubscribe = subscribeToScroll(reference, update);
392
+ tooltip3.classList.add(TOOLTIP_OPEN_CLASS);
393
+ update();
394
+ if (closeDelay > 0) {
395
+ state.timer = setTimeout(hide, closeDelay);
396
+ }
397
+ };
398
+ const handleUpdate = () => {
399
+ const activeTooltip = getActiveTooltip();
400
+ const activeReference = getActiveReference();
401
+ if (activeTooltip && !activeReference) {
402
+ hide();
403
+ return;
404
+ }
405
+ if (activeTooltip && activeReference) {
406
+ updateTooltipPosition(options, activeReference, activeTooltip);
407
+ }
408
+ };
409
+ const init = () => {
410
+ if (!initialized) {
411
+ initialized = true;
412
+ window.addEventListener("scroll", handleUpdate);
413
+ window.addEventListener("resize", handleUpdate);
414
+ }
415
+ };
416
+ const cleanup = () => {
417
+ if (initialized) {
418
+ initialized = false;
419
+ window.removeEventListener("scroll", handleUpdate);
420
+ window.removeEventListener("resize", handleUpdate);
421
+ }
422
+ };
423
+ return {
424
+ get visible() {
425
+ return Boolean(state.currentId);
426
+ },
427
+ getActiveReference,
428
+ show,
429
+ hide,
430
+ init,
431
+ cleanup
432
+ };
433
+ }
434
+ function createTooltipElement(options) {
435
+ const { text, className } = options;
436
+ const id = generateId();
437
+ const tooltip3 = document.createElement("div");
438
+ tooltip3.id = id;
439
+ tooltip3.className = className ? `${TOOLTIP_BASE_CLASS} ${className}` : TOOLTIP_BASE_CLASS;
440
+ tooltip3.setAttribute("role", "tooltip");
441
+ tooltip3.setAttribute("aria-live", "polite");
442
+ tooltip3.textContent = text;
443
+ return tooltip3;
444
+ }
445
+ function attachTooltip(tooltip3, reference) {
446
+ const container = document.querySelector(PAGE_CONTAINER_SELECTOR) || document.body;
447
+ const ariaLive = reference.getAttribute("aria-live");
448
+ reference.setAttribute(TOOLTIP_DATA_ATTR, tooltip3.id);
449
+ if (ariaLive) {
450
+ tooltip3.setAttribute("aria-live", ariaLive);
451
+ }
452
+ container.appendChild(tooltip3);
453
+ }
454
+ function detachTooltip(tooltip3) {
455
+ if (tooltip3.id) {
456
+ const reference = getReferenceByTooltipId(tooltip3.id);
457
+ reference == null ? void 0 : reference.removeAttribute(TOOLTIP_DATA_ATTR);
458
+ }
459
+ tooltip3.remove();
460
+ }
461
+ function getReferenceByTooltipId(id) {
462
+ return document.querySelector(`[${TOOLTIP_DATA_ATTR}="${id}"]`);
463
+ }
464
+ function subscribeToScroll(reference, update) {
465
+ const scrollableElement = getParentScrollableElement(reference);
466
+ scrollableElement.addEventListener("scroll", update);
467
+ return () => {
468
+ scrollableElement.removeEventListener("scroll", update);
469
+ };
470
+ }
471
+ function getParentScrollableElement(target) {
472
+ const closestScrollableParent = target.closest("table") || target.closest("code");
473
+ return closestScrollableParent || target.parentElement || document.body;
474
+ }
475
+ function createTooltipContext(referenceElement, tooltipElement) {
476
+ const tooltipParent = tooltipElement.parentElement;
477
+ if (!tooltipParent) {
478
+ return null;
479
+ }
480
+ const elements = {
481
+ reference: referenceElement,
482
+ tooltip: tooltipElement,
483
+ offsetParent: tooltipParent
484
+ };
485
+ const viewport = getViewportRect();
486
+ const reference = getElementRect(referenceElement);
487
+ const { width, height } = tooltipElement.getBoundingClientRect();
488
+ return {
489
+ isRtl: document.dir === "rtl",
490
+ viewport,
491
+ reference,
492
+ tooltip: createRect({ top: 0, left: 0, width, height }),
493
+ elements
494
+ };
495
+ }
496
+ function updateTooltipPosition(options, referenceElement, tooltipElement) {
497
+ const context = createTooltipContext(referenceElement, tooltipElement);
498
+ if (!context) {
499
+ return;
500
+ }
501
+ const coords = getTooltipCoords(context, options);
502
+ tooltipElement.style.top = `${coords.y}px`;
503
+ tooltipElement.style.left = `${coords.x}px`;
504
+ }
505
+ function getTooltipCoords(context, options) {
506
+ const { placement = "bottom-start", offset = DEFAULT_OFFSET_VALUES, flip = true } = options;
507
+ const { reference, tooltip: tooltip3, viewport, isRtl } = context;
508
+ const { coords } = computePosition(reference, tooltip3, viewport, placement, offset, isRtl, flip);
509
+ const rect = updateRect(tooltip3, { top: coords.y, left: coords.x });
510
+ const relativeRect = convertToRelativeToOffsetParentRect(rect, context.elements.offsetParent);
511
+ return {
512
+ x: relativeRect.left,
513
+ y: relativeRect.top
514
+ };
515
+ }
173
516
 
174
- // src/js/inline-code/constant.ts
175
- var INLINE_CODE = ".yfm-clipboard-inline-code";
176
- var INLINE_CODE_ID = "tooltip_inline_clipboard_dialog";
177
- var INLINE_CODE_CLASS = "yfm inline_code_tooltip";
178
- var OPEN_CLASS = "open";
179
- var LANG_TOKEN = {
517
+ // src/js/constant.ts
518
+ var COPIED_LANG_TOKEN = {
180
519
  ru: "\u0421\u043A\u043E\u043F\u0438\u0440\u043E\u0432\u0430\u043D\u043E",
181
520
  en: "Copied",
182
521
  ar: "\u062A\u0645 \u0627\u0644\u0646\u0633\u062E",
@@ -195,193 +534,56 @@
195
534
  uz: "Nusxalandi"
196
535
  };
197
536
 
198
- // src/js/term/utils.ts
199
- var Selector = {
200
- TITLE: ".yfm .yfm-term_title",
201
- CONTENT: ".yfm .yfm-term_dfn"
202
- };
203
- var openClass = "open";
204
- var openDefinitionClass = Selector.CONTENT.replace(/\./g, "") + " " + openClass;
205
- function getCoords(elem) {
206
- const box = elem.getBoundingClientRect();
207
- const body = document.body;
208
- const docEl = document.documentElement;
209
- const scrollTop = window.pageYOffset || docEl.scrollTop || body.scrollTop;
210
- const scrollLeft = window.pageXOffset || docEl.scrollLeft || body.scrollLeft;
211
- const clientTop = docEl.clientTop || body.clientTop || 0;
212
- const clientLeft = docEl.clientLeft || body.clientLeft || 0;
213
- const top = box.top + scrollTop - clientTop;
214
- const left = box.left + scrollLeft - clientLeft;
215
- return { top: Math.round(top), left: Math.round(left) };
216
- }
217
-
218
- // src/js/inline-code/utils.ts
219
- var timer = null;
220
- var isListenerNeeded = true;
221
- function getTooltipElement() {
222
- return document.getElementById(INLINE_CODE_ID);
223
- }
224
- function setTooltipAriaAttributes(tooltipElement, targetElement) {
225
- const ariaLive = targetElement.getAttribute("aria-live") || "polite";
226
- tooltipElement == null ? void 0 : tooltipElement.setAttribute("aria-live", ariaLive);
227
- tooltipElement == null ? void 0 : tooltipElement.setAttribute("aria-modal", "true");
228
- }
229
- function checkTimerAndClear() {
230
- if (timer) {
231
- clearTimeout(timer);
232
- timer = null;
233
- }
234
- }
235
- function tooltipParentElement(target) {
236
- if (!target) {
237
- return null;
238
- }
239
- const closestScrollableParent = target.closest("table") || target.closest("code");
240
- return closestScrollableParent || target.parentElement;
241
- }
242
- function tooltipOnResize() {
243
- const openedDefinition = getTooltipElement();
244
- if (!openedDefinition) {
245
- return;
246
- }
247
- const inlineId = openedDefinition.getAttribute("inline-id") || "";
248
- const targetElement = document.getElementById(inlineId);
249
- if (!targetElement) {
250
- return;
251
- }
252
- setTooltipPosition(openedDefinition, targetElement);
253
- }
254
- function setTooltipPosition(tooltipElement, targetElement) {
255
- const {
256
- x: inlineX,
257
- y: inlineY,
258
- right: inlineRight,
259
- left: inlineLeft,
260
- width: inlineWidth,
261
- height: inlineHeight
262
- } = targetElement.getBoundingClientRect();
263
- const tooltipParent = tooltipParentElement(targetElement);
264
- if (!tooltipParent) {
265
- return;
266
- }
267
- const { right: tooltipParentRight, left: tooltipParentLeft } = tooltipParent.getBoundingClientRect();
268
- if ((tooltipParentRight < inlineLeft || tooltipParentLeft > inlineRight) && !isListenerNeeded) {
269
- closeTooltip(tooltipElement);
270
- return;
271
- }
272
- if (isListenerNeeded && tooltipParent) {
273
- tooltipParent.addEventListener("scroll", tooltipOnResize);
274
- isListenerNeeded = false;
275
- }
276
- const relativeX = Number(tooltipElement.getAttribute("relativeX"));
277
- const relativeY = Number(tooltipElement.getAttribute("relativeY"));
278
- if (relativeX === inlineX && relativeY === inlineY) {
279
- return;
280
- }
281
- tooltipElement.setAttribute("relativeX", String(inlineX));
282
- tooltipElement.setAttribute("relativeY", String(inlineY));
283
- const offsetTop = inlineHeight + 5;
284
- const definitionParent = tooltipElement.parentElement;
285
- if (!definitionParent) {
286
- return;
287
- }
288
- const { width: definitionWidth } = tooltipElement.getBoundingClientRect();
289
- const { left: definitionParentLeft } = definitionParent.getBoundingClientRect();
290
- const definitionLeftCoordinate = Number(getCoords(targetElement).left);
291
- const definitionRightCoordinate = definitionWidth + definitionLeftCoordinate;
292
- const definitionOutOfScreenOnLeft = definitionLeftCoordinate - definitionWidth < 0;
293
- const definitionOutOfScreenOnRight = definitionRightCoordinate > document.body.clientWidth;
294
- const isAlignSwapped = definitionOutOfScreenOnRight || document.dir === "rtl";
295
- const fitDefinitionDocument = isAlignSwapped && !definitionOutOfScreenOnLeft ? definitionWidth - inlineWidth : 0;
296
- const customHeaderTop = getCoords(definitionParent).top - definitionParent.offsetTop;
297
- const offsetRight = 5;
298
- const shiftLeft = definitionOutOfScreenOnRight ? definitionRightCoordinate - document.body.clientWidth + offsetRight : 0;
299
- const offsetLeft = getCoords(targetElement).left - definitionParentLeft + definitionParent.offsetLeft - fitDefinitionDocument;
300
- const isShiftLeftNeeded = offsetLeft + definitionWidth >= document.body.clientWidth;
301
- tooltipElement.style.top = Number(getCoords(targetElement).top + offsetTop - customHeaderTop) + "px";
302
- tooltipElement.style.left = Number(offsetLeft - (isShiftLeftNeeded ? shiftLeft : 0)) + "px";
303
- }
304
- function getInlineCodeByTooltip(definition) {
305
- const inlineId = definition.getAttribute("inline-id");
306
- return inlineId ? document.getElementById(inlineId) : null;
307
- }
308
- function closeTooltipFn(definition) {
309
- definition.classList.remove(OPEN_CLASS);
310
- const inline = getInlineCodeByTooltip(definition);
311
- const inlineCodepParent = tooltipParentElement(inline);
312
- const tooltipParent = tooltipParentElement(definition);
313
- definition.removeAttribute("inline-id");
314
- if (!inlineCodepParent || !tooltipParent) {
315
- return;
316
- }
317
- tooltipParent.removeChild(definition);
318
- inlineCodepParent.removeEventListener("scroll", tooltipOnResize);
319
- isListenerNeeded = true;
320
- }
321
- function createTooltip() {
322
- var _a;
323
- let tooltip = getTooltipElement();
324
- if (!tooltip) {
325
- const pageContent = document.querySelector(".dc-doc-page__content") || document.body;
326
- const lang = document.documentElement.lang || "en";
327
- const tooltipText = (_a = LANG_TOKEN[lang]) != null ? _a : LANG_TOKEN.en;
328
- const host = document.createElement("div");
329
- host.innerHTML = `
330
- <div id="${INLINE_CODE_ID}" class="${INLINE_CODE_CLASS}"
331
- role="dialog" aria-live="polite" aria-modal="true">
332
- ${tooltipText}
333
- </div>
334
- `;
335
- tooltip = host.firstElementChild;
336
- pageContent.appendChild(tooltip);
537
+ // src/js/anchor.ts
538
+ var ALLOWED_PROTOCOL_RE = /^(?:https?|file):$/;
539
+ var ANCHOR_BUTTON_SELECTOR = ".yfm-clipboard-anchor";
540
+ var tooltip = createTooltipFactory();
541
+ function getLink(target) {
542
+ const href = target.nodeName === "A" ? target.href : target.dataset.href;
543
+ const link = new URL(href || "", window.location.href);
544
+ if (ALLOWED_PROTOCOL_RE.test(link.protocol)) {
545
+ return link.href;
337
546
  }
338
- return tooltip;
547
+ return window.location.href;
339
548
  }
340
- function openTooltip(target) {
341
- const tooltip = createTooltip();
342
- if (!target.matches(INLINE_CODE) || !tooltip) {
343
- return;
344
- }
345
- tooltip.setAttribute("inline-id", target.getAttribute("id") || "");
346
- setTooltipAriaAttributes(tooltip, target);
347
- setTooltipPosition(tooltip, target);
348
- if (tooltip.classList.contains(OPEN_CLASS)) {
349
- tooltip.classList.remove(OPEN_CLASS);
350
- requestAnimationFrame(() => {
351
- tooltip.classList.add(OPEN_CLASS);
549
+ if (typeof document !== "undefined") {
550
+ tooltip.init();
551
+ document.addEventListener("click", (event) => {
552
+ const target = getEventTarget(event);
553
+ if (isCustom(event) || !target.matches(ANCHOR_BUTTON_SELECTOR)) {
554
+ return;
555
+ }
556
+ const link = getLink(target);
557
+ copyToClipboard(link).then(() => {
558
+ var _a;
559
+ const lang = document.documentElement.lang || "en";
560
+ const tooltipText = (_a = COPIED_LANG_TOKEN[lang]) != null ? _a : COPIED_LANG_TOKEN.en;
561
+ tooltip.show(target, tooltipText);
352
562
  });
353
- } else {
354
- tooltip.classList.add(OPEN_CLASS);
355
- }
356
- return tooltip;
357
- }
358
- function closeTooltip(target) {
359
- checkTimerAndClear();
360
- closeTooltipFn(target);
361
- }
362
- function tooltipWorker(target) {
363
- const definition = openTooltip(target);
364
- if (!definition) {
365
- return;
366
- }
367
- checkTimerAndClear();
368
- timer = setTimeout(() => {
369
- closeTooltip(definition);
370
- timer = null;
371
- }, 1e3);
563
+ });
372
564
  }
373
565
 
374
566
  // src/js/inline-code/index.ts
567
+ var CLASS_INLINE_CODE = "yfm-clipboard-inline-code";
568
+ var INLINE_CODE = `.${CLASS_INLINE_CODE}`;
569
+ var tooltip2 = createTooltipFactory({
570
+ // NOTE: Add additional className for backward capability
571
+ additionalClassName: "inline_code_tooltip"
572
+ });
375
573
  function inlineCopyFn(target) {
376
574
  const innerText = target.innerText;
377
575
  if (!innerText) {
378
576
  return;
379
577
  }
380
578
  copyToClipboard(innerText).then(() => {
381
- tooltipWorker(target);
579
+ var _a;
580
+ const lang = document.documentElement.lang || "en";
581
+ const tooltipText = (_a = COPIED_LANG_TOKEN[lang]) != null ? _a : COPIED_LANG_TOKEN.en;
582
+ tooltip2.show(target, tooltipText);
382
583
  });
383
584
  }
384
585
  if (typeof document !== "undefined") {
586
+ tooltip2.init();
385
587
  document.addEventListener("click", (event) => {
386
588
  const target = getEventTarget(event);
387
589
  const inline = target.matches(INLINE_CODE);
@@ -391,39 +593,18 @@
391
593
  inlineCopyFn(target);
392
594
  });
393
595
  document.addEventListener("keydown", (event) => {
394
- var _a;
395
596
  if (event.key === "Enter" && document.activeElement) {
396
597
  const activeElement = document.activeElement;
397
- const classInlineCode = INLINE_CODE.replace(".", "");
398
- if (!activeElement.classList.contains(classInlineCode)) {
598
+ if (!activeElement.classList.contains(CLASS_INLINE_CODE)) {
399
599
  return;
400
600
  }
401
- const innerText = activeElement.innerText;
402
- if (!innerText) {
403
- return;
404
- }
405
- copyToClipboard(innerText).then(() => {
406
- tooltipWorker(activeElement);
407
- });
601
+ inlineCopyFn(activeElement);
408
602
  }
409
- const inlineTooltip = getTooltipElement();
410
- if (event.key === "Escape" && inlineTooltip) {
411
- closeTooltip(inlineTooltip);
412
- (_a = getInlineCodeByTooltip(inlineTooltip)) == null ? void 0 : _a.focus();
413
- }
414
- });
415
- window.addEventListener("resize", () => {
416
- const inlineTooltip = getTooltipElement();
417
- if (!inlineTooltip) {
418
- return;
419
- }
420
- const inlineId = inlineTooltip.getAttribute("inline-id") || "";
421
- const inlineCodeElement = document.getElementById(inlineId);
422
- if (!inlineCodeElement) {
423
- inlineTooltip.classList.toggle(OPEN_CLASS);
424
- return;
603
+ if (event.key === "Escape" && tooltip2.visible) {
604
+ const reference = tooltip2.getActiveReference();
605
+ tooltip2.hide();
606
+ reference == null ? void 0 : reference.focus();
425
607
  }
426
- setTooltipPosition(inlineTooltip, inlineCodeElement);
427
608
  });
428
609
  }
429
610
  })();