@diplodoc/transform 4.58.0 → 4.59.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 +57 -0
- 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 +10 -0
- package/dist/css/base.css.map +3 -3
- package/dist/css/base.min.css +1 -1
- package/dist/css/base.min.css.map +3 -3
- package/dist/css/print.css.map +1 -1
- package/dist/css/yfm.css +67 -0
- 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/_yfm-only.js.map +2 -2
- package/dist/js/_yfm-only.min.js.map +2 -2
- package/dist/js/base.js +233 -18
- package/dist/js/base.js.map +3 -3
- package/dist/js/base.min.js +1 -1
- package/dist/js/base.min.js.map +4 -4
- package/dist/js/yfm.js +213 -18
- package/dist/js/yfm.js.map +4 -4
- package/dist/js/yfm.min.js +1 -1
- package/dist/js/yfm.min.js.map +4 -4
- package/lib/frontmatter.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/plugins/changelog/index.js +2 -1
- package/lib/plugins/changelog/index.js.map +1 -1
- package/lib/plugins/images/collect.js +1 -1
- package/lib/plugins/images/collect.js.map +1 -1
- package/lib/plugins/images/index.js +3 -3
- package/lib/plugins/images/index.js.map +1 -1
- package/lib/plugins/inline-code/constant.d.ts +4 -0
- package/lib/plugins/inline-code/constant.js +58 -0
- package/lib/plugins/inline-code/constant.js.map +1 -0
- package/lib/plugins/inline-code/index.d.ts +3 -0
- package/lib/plugins/inline-code/index.js +45 -0
- package/lib/plugins/inline-code/index.js.map +1 -0
- package/lib/plugins.js +2 -0
- package/lib/plugins.js.map +1 -1
- package/lib/utils.d.ts +1 -0
- package/lib/utils.js +11 -1
- package/lib/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/js/base.ts +1 -0
- package/src/js/code.ts +32 -26
- package/src/js/inline-code/constant.ts +3 -0
- package/src/js/inline-code/index.ts +76 -0
- package/src/js/inline-code/utils.ts +190 -0
- package/src/js/term/utils.ts +1 -1
- package/src/scss/_code.scss +9 -0
- package/src/scss/_inline-code.scss +59 -0
- package/src/scss/_table.scss +12 -0
- package/src/scss/_yfm-only.scss +1 -0
- package/src/scss/brand.scss +1 -0
- package/src/scss/private.scss +2 -0
- package/src/transform/frontmatter.ts +1 -1
- package/src/transform/index.ts +0 -1
- package/src/transform/plugins/changelog/index.ts +3 -1
- package/src/transform/plugins/images/collect.ts +2 -2
- package/src/transform/plugins/images/index.ts +4 -4
- package/src/transform/plugins/inline-code/constant.ts +58 -0
- package/src/transform/plugins/inline-code/index.ts +58 -0
- package/src/transform/plugins.ts +2 -0
- package/src/transform/utils.ts +10 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LANG_TOKEN_LABEL = exports.LANG_TOKEN_DESCRIPTION = exports.LANG_TOKEN = void 0;
|
|
4
|
+
exports.LANG_TOKEN = {
|
|
5
|
+
ru: 'Скопировано',
|
|
6
|
+
en: 'Copied',
|
|
7
|
+
ar: 'تم النسخ',
|
|
8
|
+
cs: 'Zkopírováno',
|
|
9
|
+
fr: 'Copié',
|
|
10
|
+
es: 'Copiado',
|
|
11
|
+
he: 'הועתק',
|
|
12
|
+
bg: 'Копирано',
|
|
13
|
+
et: 'Kopeeritud',
|
|
14
|
+
el: 'Αντιγράφηκε',
|
|
15
|
+
pt: 'Copiado',
|
|
16
|
+
zh: '已复制',
|
|
17
|
+
'zh-tw': '已複製',
|
|
18
|
+
kk: 'Көшірілді',
|
|
19
|
+
tr: 'Kopyalandı',
|
|
20
|
+
uz: 'Nusxalandi',
|
|
21
|
+
};
|
|
22
|
+
exports.LANG_TOKEN_DESCRIPTION = {
|
|
23
|
+
ru: 'Чтобы скопировать текст внутри блока нажмите на блок',
|
|
24
|
+
en: 'To copy the text inside the block, click on the block',
|
|
25
|
+
ar: 'لنسخ النص داخل المربع، انقر على المربع',
|
|
26
|
+
cs: 'Chcete-li zkopírovat text uvnitř bloku, klikněte na blok',
|
|
27
|
+
fr: "Pour copier le texte à l'intérieur du bloc, cliquez sur le bloc",
|
|
28
|
+
es: 'Para copiar el texto dentro del bloque, haga clic en el bloque',
|
|
29
|
+
he: 'כדי להעתיק את הטקסט בתוך הבלוק, לחץ על הבלוק',
|
|
30
|
+
bg: 'За да копирате текста във блока, кликнете върху блока',
|
|
31
|
+
et: 'Teksti kopeerimiseks plokis klõpsake plokil',
|
|
32
|
+
el: 'Για να αντιγράψετε το κείμενο μέσα στο μπλοκ, κάντε κλικ στο μπλοκ',
|
|
33
|
+
pt: 'Para copiar o texto dentro do bloco, clique no bloco',
|
|
34
|
+
zh: '要复制块内的文本,请点击该块',
|
|
35
|
+
'zh-tw': '要複製區塊內的文字,請點擊該區塊',
|
|
36
|
+
kk: 'Блок ішіндегі мәтінді көшіру үшін блокты басыңыз',
|
|
37
|
+
tr: 'Blok içindeki metni kopyalamak için bloğa tıklayın',
|
|
38
|
+
uz: 'Blok ichidagi matnni nusxalash uchun blokni bosing',
|
|
39
|
+
};
|
|
40
|
+
exports.LANG_TOKEN_LABEL = {
|
|
41
|
+
ru: 'Блок кода',
|
|
42
|
+
en: 'Code block',
|
|
43
|
+
ar: 'كتلة التعليمات البرمجية',
|
|
44
|
+
cs: 'Blok kódu',
|
|
45
|
+
fr: 'Bloc de code',
|
|
46
|
+
es: 'Bloque de código',
|
|
47
|
+
he: 'בלוק קוד',
|
|
48
|
+
bg: 'Блок с код',
|
|
49
|
+
et: 'Koodiplokk',
|
|
50
|
+
el: 'Μπλοκ κώδικα',
|
|
51
|
+
pt: 'Bloco de código',
|
|
52
|
+
zh: '代码块',
|
|
53
|
+
'zh-tw': '代碼區塊',
|
|
54
|
+
kk: 'Код блогы',
|
|
55
|
+
tr: 'Kod bloğu',
|
|
56
|
+
uz: 'Kod bloki',
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=constant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constant.js","sourceRoot":"","sources":["../../../src/transform/plugins/inline-code/constant.ts"],"names":[],"mappings":";;;AAEa,QAAA,UAAU,GAAyB;IAC5C,EAAE,EAAE,aAAa;IACjB,EAAE,EAAE,QAAQ;IACZ,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,aAAa;IACjB,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,SAAS;IACb,EAAE,EAAE,OAAO;IACX,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,YAAY;IAChB,EAAE,EAAE,aAAa;IACjB,EAAE,EAAE,SAAS;IACb,EAAE,EAAE,KAAK;IACT,OAAO,EAAE,KAAK;IACd,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,YAAY;IAChB,EAAE,EAAE,YAAY;CACnB,CAAC;AAEW,QAAA,sBAAsB,GAAyB;IACxD,EAAE,EAAE,sDAAsD;IAC1D,EAAE,EAAE,uDAAuD;IAC3D,EAAE,EAAE,wCAAwC;IAC5C,EAAE,EAAE,0DAA0D;IAC9D,EAAE,EAAE,iEAAiE;IACrE,EAAE,EAAE,gEAAgE;IACpE,EAAE,EAAE,8CAA8C;IAClD,EAAE,EAAE,uDAAuD;IAC3D,EAAE,EAAE,6CAA6C;IACjD,EAAE,EAAE,oEAAoE;IACxE,EAAE,EAAE,sDAAsD;IAC1D,EAAE,EAAE,gBAAgB;IACpB,OAAO,EAAE,kBAAkB;IAC3B,EAAE,EAAE,kDAAkD;IACtD,EAAE,EAAE,oDAAoD;IACxD,EAAE,EAAE,oDAAoD;CAC3D,CAAC;AAEW,QAAA,gBAAgB,GAAyB;IAClD,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,YAAY;IAChB,EAAE,EAAE,yBAAyB;IAC7B,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,cAAc;IAClB,EAAE,EAAE,kBAAkB;IACtB,EAAE,EAAE,UAAU;IACd,EAAE,EAAE,YAAY;IAChB,EAAE,EAAE,YAAY;IAChB,EAAE,EAAE,cAAc;IAClB,EAAE,EAAE,iBAAiB;IACrB,EAAE,EAAE,KAAK;IACT,OAAO,EAAE,MAAM;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;IACf,EAAE,EAAE,WAAW;CAClB,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const utils_1 = require("../utils");
|
|
3
|
+
const constant_1 = require("./constant");
|
|
4
|
+
const inlineCode = (md, options) => {
|
|
5
|
+
const lang = options.lang;
|
|
6
|
+
md.renderer.rules.code_inline = function (tokens, idx) {
|
|
7
|
+
var _a, _b;
|
|
8
|
+
const id = (0, utils_1.generateID)();
|
|
9
|
+
const description = (_a = constant_1.LANG_TOKEN_DESCRIPTION[lang]) !== null && _a !== void 0 ? _a : constant_1.LANG_TOKEN_DESCRIPTION.en;
|
|
10
|
+
const label = (_b = constant_1.LANG_TOKEN_LABEL[lang]) !== null && _b !== void 0 ? _b : constant_1.LANG_TOKEN_LABEL.en;
|
|
11
|
+
return `<code class="yfm-clipboard-inline-code" role="button" aria-label="${label}" aria-description="${description}" tabindex='0' id="${id}">${tokens[idx].content}</code>`;
|
|
12
|
+
};
|
|
13
|
+
md.core.ruler.after('inline', 'tooltip_code_inline', (state) => {
|
|
14
|
+
var _a;
|
|
15
|
+
const tokens = state.tokens;
|
|
16
|
+
for (let i = 0; i !== tokens.length; i++) {
|
|
17
|
+
const token = tokens[i];
|
|
18
|
+
if (token.type !== 'inline') {
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
if (!token.children || token.children.every((e) => e.type !== 'code_inline')) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
const child = token.children.find((e) => e.type === 'code_inline');
|
|
25
|
+
if (!child) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const dialog = new state.Token('tooltip_open', 'div', 1);
|
|
29
|
+
dialog.attrSet('class', 'yfm inline_code_tooltip');
|
|
30
|
+
dialog.attrSet('id', `tooltip_inline_clipboard_dialog`);
|
|
31
|
+
dialog.attrSet('role', 'dialog');
|
|
32
|
+
dialog.attrSet('aria-live', 'polite');
|
|
33
|
+
dialog.attrSet('aria-modal', 'true');
|
|
34
|
+
tokens.push(dialog);
|
|
35
|
+
const text = new state.Token('text', '', 0);
|
|
36
|
+
text.content = (_a = constant_1.LANG_TOKEN[lang]) !== null && _a !== void 0 ? _a : constant_1.LANG_TOKEN.en;
|
|
37
|
+
tokens.push(text);
|
|
38
|
+
const closeDialog = new state.Token('tooltip_close', 'div', -1);
|
|
39
|
+
tokens.push(closeDialog);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
module.exports = inlineCode;
|
|
45
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/transform/plugins/inline-code/index.ts"],"names":[],"mappings":";AACA,oCAAoC;AAEpC,yCAAgF;AAEhF,MAAM,UAAU,GAAuB,CAAC,EAAE,EAAE,OAAO,EAAE,EAAE;IACnD,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAE1B,EAAE,CAAC,QAAQ,CAAC,KAAK,CAAC,WAAW,GAAG,UAAU,MAAM,EAAE,GAAG;;QACjD,MAAM,EAAE,GAAG,IAAA,kBAAU,GAAE,CAAC;QAExB,MAAM,WAAW,GAAG,MAAA,iCAAsB,CAAC,IAAI,CAAC,mCAAI,iCAAsB,CAAC,EAAE,CAAC;QAC9E,MAAM,KAAK,GAAG,MAAA,2BAAgB,CAAC,IAAI,CAAC,mCAAI,2BAAgB,CAAC,EAAE,CAAC;QAE5D,OAAO,qEAAqE,KAAK,uBAAuB,WAAW,sBAAsB,EAAE,KAA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AAM,CAAC,CAAC;YAEpB,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC;YAC5C,IAAI,CAAC,OAAO,GAAG,MAAA,qBAAU,CAAC,IAAI,CAAC,mCAAI,qBAAU,CAAC,EAAE,CAAC;YACjD,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAElB,MAAM,WAAW,GAAG,IAAI,KAAK,CAAC,KAAK,CAAC,eAAe,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;YAChE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;YACzB,MAAM;SACT;IACL,CAAC,CAAC,CAAC;AACP,CAAC,CAAC;AAEF,iBAAS,UAAU,CAAC"}
|
package/lib/plugins.js
CHANGED
|
@@ -17,6 +17,7 @@ const file_1 = __importDefault(require("./plugins/file"));
|
|
|
17
17
|
const imsize_1 = __importDefault(require("./plugins/imsize"));
|
|
18
18
|
const term_1 = __importDefault(require("./plugins/term"));
|
|
19
19
|
const block_anchor_1 = __importDefault(require("./plugins/block-anchor"));
|
|
20
|
+
const inline_code_1 = __importDefault(require("./plugins/inline-code"));
|
|
20
21
|
const defaultPlugins = [
|
|
21
22
|
meta_1.default,
|
|
22
23
|
deflist_1.default,
|
|
@@ -33,6 +34,7 @@ const defaultPlugins = [
|
|
|
33
34
|
imsize_1.default,
|
|
34
35
|
term_1.default,
|
|
35
36
|
block_anchor_1.default,
|
|
37
|
+
inline_code_1.default,
|
|
36
38
|
];
|
|
37
39
|
module.exports = defaultPlugins;
|
|
38
40
|
//# sourceMappingURL=plugins.js.map
|
package/lib/plugins.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugins.js","sourceRoot":"","sources":["../src/transform/plugins.ts"],"names":[],"mappings":";;;;AAEA,0DAAkC;AAClC,gEAAwC;AACxC,wDAAgC;AAChC,4DAAoC;AACpC,gEAAwC;AACxC,0DAAkC;AAClC,0DAAkC;AAClC,wDAAgC;AAChC,4DAAoC;AACpC,oEAA4C;AAC5C,4DAAuC;AACvC,0DAAkC;AAClC,8DAAsC;AACtC,0DAAkC;AAClC,0EAAiD;
|
|
1
|
+
{"version":3,"file":"plugins.js","sourceRoot":"","sources":["../src/transform/plugins.ts"],"names":[],"mappings":";;;;AAEA,0DAAkC;AAClC,gEAAwC;AACxC,wDAAgC;AAChC,4DAAoC;AACpC,gEAAwC;AACxC,0DAAkC;AAClC,0DAAkC;AAClC,wDAAgC;AAChC,4DAAoC;AACpC,oEAA4C;AAC5C,4DAAuC;AACvC,0DAAkC;AAClC,8DAAsC;AACtC,0DAAkC;AAClC,0EAAiD;AACjD,wEAA+C;AAE/C,MAAM,cAAc,GAAG;IACnB,cAAI;IACJ,iBAAO;IACP,aAAG;IACH,eAAK;IACL,iBAAO;IACP,cAAI;IACJ,cAAI;IACJ,aAAG;IACH,eAAK;IACL,mBAAS;IACT,eAAQ;IACR,cAAI;IACJ,gBAAM;IACN,cAAI;IACJ,sBAAW;IACX,qBAAU;CACW,CAAC;AAE1B,iBAAS,cAAc,CAAC"}
|
package/lib/utils.d.ts
CHANGED
|
@@ -11,5 +11,6 @@ export declare function transformLinkToOriginalArticle(opts: {
|
|
|
11
11
|
currentPath: string;
|
|
12
12
|
}): string;
|
|
13
13
|
export declare function getHrefTokenAttr(token: Token): string;
|
|
14
|
+
export declare function getSrcTokenAttr(token: Token): string;
|
|
14
15
|
export declare const PAGE_LINK_REGEXP: RegExp;
|
|
15
16
|
export declare function defaultTransformLink(href: string): string;
|
package/lib/utils.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.defaultTransformLink = exports.PAGE_LINK_REGEXP = exports.getHrefTokenAttr = exports.transformLinkToOriginalArticle = exports.isExternalHref = exports.headingInfo = exports.findBlockTokens = exports.isLocalUrl = void 0;
|
|
6
|
+
exports.defaultTransformLink = exports.PAGE_LINK_REGEXP = exports.getSrcTokenAttr = exports.getHrefTokenAttr = exports.transformLinkToOriginalArticle = exports.isExternalHref = exports.headingInfo = exports.findBlockTokens = exports.isLocalUrl = void 0;
|
|
7
7
|
const url_1 = __importDefault(require("url"));
|
|
8
8
|
function isLocalUrl(url) {
|
|
9
9
|
return !/^(?:[a-z]+:)?\/\//i.test(url);
|
|
@@ -80,6 +80,16 @@ function getHrefTokenAttr(token) {
|
|
|
80
80
|
return href;
|
|
81
81
|
}
|
|
82
82
|
exports.getHrefTokenAttr = getHrefTokenAttr;
|
|
83
|
+
function getSrcTokenAttr(token) {
|
|
84
|
+
let src = token.attrGet('src') || '';
|
|
85
|
+
try {
|
|
86
|
+
// decodeURI can throw an error https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/URIError
|
|
87
|
+
src = decodeURI(src);
|
|
88
|
+
}
|
|
89
|
+
catch (e) { }
|
|
90
|
+
return src;
|
|
91
|
+
}
|
|
92
|
+
exports.getSrcTokenAttr = getSrcTokenAttr;
|
|
83
93
|
exports.PAGE_LINK_REGEXP = /\.(md|ya?ml)$/i;
|
|
84
94
|
function defaultTransformLink(href) {
|
|
85
95
|
var _a;
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/transform/utils.ts"],"names":[],"mappings":";;;;;;AAEA,8CAAsB;AAEtB,SAAgB,UAAU,CAAC,GAAW;IAClC,OAAO,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC3C,CAAC;AAFD,gCAEC;AAED,SAAgB,eAAe,CAAC,MAAe,EAAE,EAAU;IACvD,IAAI,WAAW,GAAY,EAAE,CAAC;IAC9B,IAAI,CAAC,GAAG,CAAC,EACL,UAAU,EACV,KAAK,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AAG,CAAC,MAAM,iCACV,MAAM,KACT,QAAQ,EAAE,MAAA,MAAM,CAAC,QAAQ,0CAAE,OAAO,CAAC,wBAAgB,EAAE,OAAO,CAAC,IAC/D,CAAC;IAEH,OAAO,IAAI,CAAC;AAChB,CAAC;AARD,oDAQC"}
|
package/package.json
CHANGED
package/src/js/base.ts
CHANGED
package/src/js/code.ts
CHANGED
|
@@ -18,39 +18,45 @@ function notifySuccess(svgButton: HTMLElement | null) {
|
|
|
18
18
|
icon.beginElement();
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
+
function buttonCopyFn(target: HTMLElement) {
|
|
22
|
+
const parent = target.parentNode;
|
|
23
|
+
|
|
24
|
+
if (!parent) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const code = parent.querySelector<HTMLElement>('pre code');
|
|
29
|
+
if (!code) {
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Get all text nodes and filter out line numbers
|
|
34
|
+
const textContent = Array.from(code.childNodes)
|
|
35
|
+
.filter((node) => {
|
|
36
|
+
// Skip line number spans
|
|
37
|
+
if (node instanceof HTMLElement && node.classList.contains('yfm-line-number')) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
return true;
|
|
41
|
+
})
|
|
42
|
+
.map((node) => node.textContent)
|
|
43
|
+
.join('');
|
|
44
|
+
|
|
45
|
+
copyToClipboard(textContent).then(() => {
|
|
46
|
+
notifySuccess(parent.querySelector('.yfm-clipboard-icon'));
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
21
50
|
if (typeof document !== 'undefined') {
|
|
22
51
|
document.addEventListener('click', (event) => {
|
|
23
52
|
const target = getEventTarget(event) as HTMLElement;
|
|
24
53
|
|
|
25
|
-
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const parent = target.parentNode;
|
|
30
|
-
|
|
31
|
-
if (!parent) {
|
|
32
|
-
return;
|
|
33
|
-
}
|
|
54
|
+
const button = target.matches(BUTTON_SELECTOR);
|
|
34
55
|
|
|
35
|
-
|
|
36
|
-
if (!code) {
|
|
56
|
+
if (isCustom(event) || !button) {
|
|
37
57
|
return;
|
|
38
58
|
}
|
|
39
59
|
|
|
40
|
-
|
|
41
|
-
const textContent = Array.from(code.childNodes)
|
|
42
|
-
.filter((node) => {
|
|
43
|
-
// Skip line number spans
|
|
44
|
-
if (node instanceof HTMLElement && node.classList.contains('yfm-line-number')) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
return true;
|
|
48
|
-
})
|
|
49
|
-
.map((node) => node.textContent)
|
|
50
|
-
.join('');
|
|
51
|
-
|
|
52
|
-
copyToClipboard(textContent).then(() => {
|
|
53
|
-
notifySuccess(parent.querySelector('.yfm-clipboard-icon'));
|
|
54
|
-
});
|
|
60
|
+
buttonCopyFn(target);
|
|
55
61
|
});
|
|
56
62
|
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {copyToClipboard, getEventTarget, isCustom} from '../utils';
|
|
2
|
+
|
|
3
|
+
import {INLINE_CODE, OPEN_CLASS} from './constant';
|
|
4
|
+
import {
|
|
5
|
+
closeTooltip,
|
|
6
|
+
getInlineCodeByTooltip,
|
|
7
|
+
getTooltipElement,
|
|
8
|
+
setTooltipPosition,
|
|
9
|
+
tooltipWorker,
|
|
10
|
+
} from './utils';
|
|
11
|
+
|
|
12
|
+
export function inlineCopyFn(target: HTMLElement) {
|
|
13
|
+
const innerText = target.innerText;
|
|
14
|
+
|
|
15
|
+
if (!innerText) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
copyToClipboard(innerText).then(() => {
|
|
20
|
+
tooltipWorker(target);
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (typeof document !== 'undefined') {
|
|
25
|
+
document.addEventListener('click', (event) => {
|
|
26
|
+
const target = getEventTarget(event) as HTMLElement;
|
|
27
|
+
|
|
28
|
+
const inline = target.matches(INLINE_CODE);
|
|
29
|
+
|
|
30
|
+
if (isCustom(event) || !inline) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
inlineCopyFn(target);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
document.addEventListener('keydown', (event) => {
|
|
38
|
+
if (event.key === 'Enter' && document.activeElement) {
|
|
39
|
+
const activeElement = document.activeElement as HTMLElement;
|
|
40
|
+
|
|
41
|
+
const innerText = activeElement.innerText;
|
|
42
|
+
|
|
43
|
+
if (!innerText) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
copyToClipboard(innerText).then(() => {
|
|
48
|
+
tooltipWorker(activeElement);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const inlineTooltip = getTooltipElement();
|
|
53
|
+
|
|
54
|
+
if (event.key === 'Escape' && inlineTooltip) {
|
|
55
|
+
closeTooltip(inlineTooltip);
|
|
56
|
+
getInlineCodeByTooltip(inlineTooltip)?.focus(); // Set focus back to open button after closing popup
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
window.addEventListener('resize', () => {
|
|
61
|
+
const inlineTooltip = getTooltipElement();
|
|
62
|
+
if (!inlineTooltip) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const inlineId = inlineTooltip.getAttribute('inline-id') || '';
|
|
67
|
+
const inlineCodeElement = document.getElementById(inlineId);
|
|
68
|
+
|
|
69
|
+
if (!inlineCodeElement) {
|
|
70
|
+
inlineTooltip.classList.toggle(OPEN_CLASS);
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
setTooltipPosition(inlineTooltip, inlineCodeElement);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
import {getCoords} from '../term/utils';
|
|
2
|
+
|
|
3
|
+
import {OPEN_CLASS} from './constant';
|
|
4
|
+
|
|
5
|
+
export let timer: ReturnType<typeof setTimeout> | null = null;
|
|
6
|
+
|
|
7
|
+
let isListenerNeeded = true;
|
|
8
|
+
|
|
9
|
+
export function getTooltipElement(): HTMLElement | null {
|
|
10
|
+
return document.querySelector('.yfm-inline-code-tooltip');
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function setTooltipAriaAttributes(tooltipElement: HTMLElement, targetElement: HTMLElement): void {
|
|
14
|
+
const ariaLive = targetElement.getAttribute('aria-live') || 'polite';
|
|
15
|
+
tooltipElement?.setAttribute('aria-live', ariaLive);
|
|
16
|
+
tooltipElement?.setAttribute('aria-modal', 'true');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
function checkTimerAndClear() {
|
|
20
|
+
if (timer) {
|
|
21
|
+
clearTimeout(timer);
|
|
22
|
+
timer = null;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function tooltipParentElement(target: HTMLElement | null) {
|
|
27
|
+
if (!target) {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const closestScrollableParent = target.closest('table') || target.closest('code');
|
|
32
|
+
|
|
33
|
+
return closestScrollableParent || target.parentElement;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function tooltipOnResize() {
|
|
37
|
+
const openedDefinition = getTooltipElement();
|
|
38
|
+
|
|
39
|
+
if (!openedDefinition) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const inlineId = openedDefinition.getAttribute('inline-id') || '';
|
|
43
|
+
const targetElement = document.getElementById(inlineId);
|
|
44
|
+
|
|
45
|
+
if (!targetElement) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
setTooltipPosition(openedDefinition, targetElement);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export function setTooltipPosition(tooltipElement: HTMLElement, targetElement: HTMLElement): void {
|
|
53
|
+
const {
|
|
54
|
+
x: inlineX,
|
|
55
|
+
y: inlineY,
|
|
56
|
+
right: inlineRight,
|
|
57
|
+
left: inlineLeft,
|
|
58
|
+
width: inlineWidth,
|
|
59
|
+
height: inlineHeight,
|
|
60
|
+
} = targetElement.getBoundingClientRect();
|
|
61
|
+
|
|
62
|
+
const tooltipParent = tooltipParentElement(targetElement);
|
|
63
|
+
|
|
64
|
+
if (!tooltipParent) {
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const {right: tooltipParentRight, left: tooltipParentLeft} =
|
|
69
|
+
tooltipParent.getBoundingClientRect();
|
|
70
|
+
|
|
71
|
+
if ((tooltipParentRight < inlineLeft || tooltipParentLeft > inlineRight) && !isListenerNeeded) {
|
|
72
|
+
closeTooltip(tooltipElement);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
if (isListenerNeeded && tooltipParent) {
|
|
77
|
+
tooltipParent.addEventListener('scroll', tooltipOnResize);
|
|
78
|
+
isListenerNeeded = false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const relativeX = Number(tooltipElement.getAttribute('relativeX'));
|
|
82
|
+
const relativeY = Number(tooltipElement.getAttribute('relativeY'));
|
|
83
|
+
|
|
84
|
+
if (relativeX === inlineX && relativeY === inlineY) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
tooltipElement.setAttribute('relativeX', String(inlineX));
|
|
89
|
+
tooltipElement.setAttribute('relativeY', String(inlineY));
|
|
90
|
+
|
|
91
|
+
const offsetTop = inlineHeight + 5;
|
|
92
|
+
const definitionParent = tooltipElement.parentElement;
|
|
93
|
+
|
|
94
|
+
if (!definitionParent) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const {width: definitionWidth} = tooltipElement.getBoundingClientRect();
|
|
99
|
+
const {left: definitionParentLeft} = definitionParent.getBoundingClientRect();
|
|
100
|
+
|
|
101
|
+
// If definition not fit document change base alignment
|
|
102
|
+
const definitionLeftCoordinate = Number(getCoords(targetElement).left);
|
|
103
|
+
const definitionRightCoordinate = definitionWidth + definitionLeftCoordinate;
|
|
104
|
+
|
|
105
|
+
const definitionOutOfScreenOnLeft = definitionLeftCoordinate - definitionWidth < 0;
|
|
106
|
+
const definitionOutOfScreenOnRight = definitionRightCoordinate > document.body.clientWidth;
|
|
107
|
+
|
|
108
|
+
const isAlignSwapped = definitionOutOfScreenOnRight || document.dir === 'rtl';
|
|
109
|
+
const fitDefinitionDocument =
|
|
110
|
+
isAlignSwapped && !definitionOutOfScreenOnLeft ? definitionWidth - inlineWidth : 0;
|
|
111
|
+
const customHeaderTop = getCoords(definitionParent).top - definitionParent.offsetTop;
|
|
112
|
+
const offsetRight = 5;
|
|
113
|
+
const shiftLeft = definitionOutOfScreenOnRight
|
|
114
|
+
? definitionRightCoordinate - document.body.clientWidth + offsetRight
|
|
115
|
+
: 0;
|
|
116
|
+
const offsetLeft =
|
|
117
|
+
getCoords(targetElement).left -
|
|
118
|
+
definitionParentLeft +
|
|
119
|
+
definitionParent.offsetLeft -
|
|
120
|
+
fitDefinitionDocument;
|
|
121
|
+
|
|
122
|
+
const isShiftLeftNeeded = offsetLeft + definitionWidth >= document.body.clientWidth;
|
|
123
|
+
|
|
124
|
+
tooltipElement.style.top =
|
|
125
|
+
Number(getCoords(targetElement).top + offsetTop - customHeaderTop) + 'px';
|
|
126
|
+
tooltipElement.style.left = Number(offsetLeft - (isShiftLeftNeeded ? shiftLeft : 0)) + 'px';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function getInlineCodeByTooltip(definition: HTMLElement) {
|
|
130
|
+
const inlineId = definition.getAttribute('inline-id');
|
|
131
|
+
|
|
132
|
+
return inlineId ? document.getElementById(inlineId) : null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function closeTooltipFn(definition: HTMLElement) {
|
|
136
|
+
definition.classList.remove(OPEN_CLASS);
|
|
137
|
+
const inline = getInlineCodeByTooltip(definition);
|
|
138
|
+
const tooltipParent = tooltipParentElement(inline);
|
|
139
|
+
|
|
140
|
+
definition.removeAttribute('inline-id');
|
|
141
|
+
|
|
142
|
+
if (!tooltipParent) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
tooltipParent.removeEventListener('scroll', tooltipOnResize);
|
|
147
|
+
isListenerNeeded = true;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export function openTooltip(target: HTMLElement) {
|
|
151
|
+
const tooltipElement = document.getElementById('tooltip_inline_clipboard_dialog');
|
|
152
|
+
|
|
153
|
+
if (!target.matches('.yfm-clipboard-inline-code') || !tooltipElement) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
tooltipElement.setAttribute('inline-id', target.getAttribute('id') || '');
|
|
158
|
+
setTooltipAriaAttributes(tooltipElement, target);
|
|
159
|
+
setTooltipPosition(tooltipElement, target);
|
|
160
|
+
|
|
161
|
+
// In order not to get rid of the smooth appearance effect, I had to do this
|
|
162
|
+
if (tooltipElement.classList.contains(OPEN_CLASS)) {
|
|
163
|
+
tooltipElement.classList.remove(OPEN_CLASS);
|
|
164
|
+
requestAnimationFrame(() => {
|
|
165
|
+
tooltipElement.classList.add(OPEN_CLASS);
|
|
166
|
+
});
|
|
167
|
+
} else {
|
|
168
|
+
tooltipElement.classList.add(OPEN_CLASS);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
return tooltipElement;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
export function closeTooltip(target: HTMLElement) {
|
|
175
|
+
checkTimerAndClear();
|
|
176
|
+
closeTooltipFn(target);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
export function tooltipWorker(target: HTMLElement) {
|
|
180
|
+
const definition = openTooltip(target);
|
|
181
|
+
|
|
182
|
+
if (!definition) {
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
checkTimerAndClear();
|
|
186
|
+
timer = setTimeout(() => {
|
|
187
|
+
closeTooltip(definition);
|
|
188
|
+
timer = null;
|
|
189
|
+
}, 1000);
|
|
190
|
+
}
|
package/src/js/term/utils.ts
CHANGED
|
@@ -172,7 +172,7 @@ export function closeDefinition(definition: HTMLElement) {
|
|
|
172
172
|
isListenerNeeded = true;
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
function getCoords(elem: HTMLElement) {
|
|
175
|
+
export function getCoords(elem: HTMLElement) {
|
|
176
176
|
const box = elem.getBoundingClientRect();
|
|
177
177
|
|
|
178
178
|
const body = document.body;
|
package/src/scss/_code.scss
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
.inline_code_tooltip {
|
|
2
|
+
position: absolute;
|
|
3
|
+
z-index: 100;
|
|
4
|
+
|
|
5
|
+
width: fit-content;
|
|
6
|
+
max-width: 450px;
|
|
7
|
+
|
|
8
|
+
@media screen and (max-width: 600px) {
|
|
9
|
+
& {
|
|
10
|
+
max-width: 80%;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
visibility: hidden;
|
|
15
|
+
opacity: 0;
|
|
16
|
+
|
|
17
|
+
padding: 10px;
|
|
18
|
+
|
|
19
|
+
background-color: var(--yfm-color-term-dfn-background);
|
|
20
|
+
|
|
21
|
+
font-size: inherit;
|
|
22
|
+
line-height: inherit;
|
|
23
|
+
font-style: normal;
|
|
24
|
+
|
|
25
|
+
border-radius: 4px;
|
|
26
|
+
|
|
27
|
+
box-shadow: 0 8px 20px var(--yfm-color-term-dfn-shadow);
|
|
28
|
+
outline: none;
|
|
29
|
+
|
|
30
|
+
&::before {
|
|
31
|
+
content: '';
|
|
32
|
+
position: absolute;
|
|
33
|
+
z-index: -1;
|
|
34
|
+
inset: 0;
|
|
35
|
+
|
|
36
|
+
border-radius: inherit;
|
|
37
|
+
box-shadow: 0 0 0 1px var(--yfm-color-term-dfn-pseudo-shadow);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
&.open {
|
|
41
|
+
visibility: visible;
|
|
42
|
+
|
|
43
|
+
animation-name: popup;
|
|
44
|
+
animation-duration: 0.1s;
|
|
45
|
+
animation-timing-function: ease-out;
|
|
46
|
+
animation-fill-mode: forwards;
|
|
47
|
+
|
|
48
|
+
@keyframes popup {
|
|
49
|
+
0% {
|
|
50
|
+
opacity: 0;
|
|
51
|
+
transform: translateY(10px);
|
|
52
|
+
}
|
|
53
|
+
100% {
|
|
54
|
+
opacity: 1;
|
|
55
|
+
transform: translateY(0);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/scss/_table.scss
CHANGED
package/src/scss/_yfm-only.scss
CHANGED
package/src/scss/brand.scss
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
--yfm-color-inline-code: var(--yfm-color-inline-code-private);
|
|
16
16
|
--yfm-color-inline-code-background: var(--yfm-color-inline-code-background-private);
|
|
17
17
|
--yfm-color-code-background: var(--yfm-color-code-background-private);
|
|
18
|
+
--yfm-color-code-hovered-background: var(--yfm-color-code-hovered-background-private);
|
|
18
19
|
|
|
19
20
|
--yfm-color-hljs-background: var(--yfm-color-hljs-background-private);
|
|
20
21
|
--yfm-color-hljs-subst: var(--yfm-color-hljs-subst-private);
|