@diplodoc/folding-headings-extension 0.1.0 → 0.1.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@diplodoc/folding-headings-extension",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Folding headings extension for Diplodoc platform ",
5
5
  "main": "build/plugin/index.js",
6
6
  "types": "build/plugin/index.d.ts",
@@ -1,9 +0,0 @@
1
- export declare const DATA_KEY = "heading-section";
2
- export declare const SectionAttr: {
3
- readonly DataId: "data-diplodoc-id";
4
- readonly DataKey: "data-diplodoc-key";
5
- };
6
- export declare const SectionCN: {
7
- Section: string;
8
- Content: string;
9
- };
@@ -1,13 +0,0 @@
1
- export { SectionCN, DATA_KEY, SectionAttr } from '../common/const';
2
- export declare const ENV_FLAG_NAME = "has-folding-headings";
3
- export declare const TokenType: {
4
- readonly Heading: "heading";
5
- readonly HeadingOpen: "heading_open";
6
- readonly HeadingClose: "heading_close";
7
- readonly Section: "heading_section";
8
- readonly SectionOpen: "heading_section_open";
9
- readonly SectionClose: "heading_section_close";
10
- readonly Content: "heading_section_content";
11
- readonly ContentOpen: "heading_section_content_open";
12
- readonly ContentClose: "heading_section_content_close";
13
- };
@@ -1,2 +0,0 @@
1
- import type ParserBlock from 'markdown-it/lib/parser_block';
2
- export declare const headingBlockRule: ParserBlock.RuleBlock;
@@ -1,3 +0,0 @@
1
- export type { TransformOptions } from './transform';
2
- export { transform } from './transform';
3
- export { TokenType } from './const';
@@ -1,297 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
-
20
- // src/plugin/index.ts
21
- var plugin_exports = {};
22
- __export(plugin_exports, {
23
- TokenType: () => TokenType,
24
- transform: () => transform
25
- });
26
- module.exports = __toCommonJS(plugin_exports);
27
-
28
- // src/common/const.ts
29
- var DATA_KEY = "heading-section";
30
- var SectionAttr = {
31
- DataId: "data-diplodoc-id",
32
- DataKey: "data-diplodoc-key"
33
- };
34
- var SectionCN = {
35
- Section: "heading-section",
36
- Content: "heading-section-content"
37
- };
38
-
39
- // src/plugin/const.ts
40
- var ENV_FLAG_NAME = "has-folding-headings";
41
- var TokenType = {
42
- Heading: "heading",
43
- HeadingOpen: "heading_open",
44
- HeadingClose: "heading_close",
45
- Section: "heading_section",
46
- SectionOpen: "heading_section_open",
47
- SectionClose: "heading_section_close",
48
- Content: "heading_section_content",
49
- ContentOpen: "heading_section_content_open",
50
- ContentClose: "heading_section_content_close"
51
- };
52
-
53
- // src/plugin/headingBlockRule.ts
54
- var headingBlockRule = (state, startLine, _endLine, silent) => {
55
- const { isSpace } = state.md.utils;
56
- let pos = state.bMarks[startLine] + state.tShift[startLine];
57
- let max = state.eMarks[startLine];
58
- if (state.sCount[startLine] - state.blkIndent >= 4) {
59
- return false;
60
- }
61
- let ch = state.src.charCodeAt(pos);
62
- if (ch !== 35 || pos >= max) {
63
- return false;
64
- }
65
- let level = 1;
66
- ch = state.src.charCodeAt(++pos);
67
- while (ch === 35 && pos < max && level <= 6) {
68
- level++;
69
- ch = state.src.charCodeAt(++pos);
70
- }
71
- let folding = false;
72
- if (ch === 43) {
73
- folding = true;
74
- ch = state.src.charCodeAt(++pos);
75
- }
76
- if (level > 6 || pos < max && !isSpace(ch)) {
77
- return false;
78
- }
79
- if (silent) {
80
- return true;
81
- }
82
- max = state.skipSpacesBack(max, pos);
83
- const tmp = state.skipCharsBack(max, 35, pos);
84
- if (tmp > pos && isSpace(state.src.charCodeAt(tmp - 1))) {
85
- max = tmp;
86
- }
87
- state.line = startLine + 1;
88
- let token = state.push(TokenType.HeadingOpen, "h" + String(level), 1);
89
- token.markup = "########".slice(0, level) + (folding ? "+" : "");
90
- token.map = [startLine, state.line];
91
- if (folding) {
92
- token.meta ||= {};
93
- token.meta.folding = true;
94
- }
95
- token = state.push("inline", "", 0);
96
- token.content = state.src.slice(pos, max).trim();
97
- token.map = [startLine, state.line];
98
- token.children = [];
99
- token = state.push(TokenType.HeadingClose, "h" + String(level), -1);
100
- token.markup = "########".slice(0, level) + (folding ? "+" : "");
101
- if (folding) {
102
- token.meta ||= {};
103
- token.meta.folding = true;
104
- }
105
- return true;
106
- };
107
-
108
- // src/plugin/utils.ts
109
- function generateID() {
110
- return DATA_KEY + "-" + Math.random().toString(36).substr(2, 8);
111
- }
112
- function headingLevel(header) {
113
- return parseInt(header.charAt(1), 10);
114
- }
115
- function last(arr) {
116
- return arr[arr.length - 1];
117
- }
118
- function hidden(box, field, value) {
119
- if (!(field in box)) {
120
- Object.defineProperty(box, field, {
121
- enumerable: false,
122
- value
123
- });
124
- }
125
- return box;
126
- }
127
- function copyRuntime({ runtime, output }, cache) {
128
- const PATH_TO_RUNTIME = "../runtime";
129
- const { join, resolve } = dynrequire("node:path");
130
- const runtimeFiles = {
131
- "index.js": runtime.script,
132
- "index.css": runtime.style
133
- };
134
- for (const [originFile, outputFile] of Object.entries(runtimeFiles)) {
135
- const file = join(PATH_TO_RUNTIME, originFile);
136
- if (!cache.has(file)) {
137
- cache.add(file);
138
- copy(resolve(__dirname, file), join(output, outputFile));
139
- }
140
- }
141
- }
142
- function copy(from, to) {
143
- const { mkdirSync, copyFileSync } = dynrequire("node:fs");
144
- const { dirname } = dynrequire("node:path");
145
- mkdirSync(dirname(to), { recursive: true });
146
- copyFileSync(from, to);
147
- }
148
- function dynrequire(module) {
149
- return eval(`require('${module}')`);
150
- }
151
-
152
- // src/plugin/sectionsCoreRule.ts
153
- var sectionsCoreRule = (state) => {
154
- const Token = state.Token;
155
- const tokens = [];
156
- const sections = [];
157
- let nestedLevel = 0;
158
- for (const token of state.tokens) {
159
- if (token.type.search(TokenType.Heading) !== 0) {
160
- nestedLevel += token.nesting;
161
- }
162
- if (last(sections) && nestedLevel < last(sections).nesting) {
163
- closeSectionsToCurrentNesting(nestedLevel);
164
- }
165
- const hasFolding = token.markup.endsWith("#+");
166
- if (token.type === TokenType.HeadingOpen) {
167
- const section = {
168
- header: headingLevel(token.tag),
169
- nesting: nestedLevel
170
- };
171
- closeSections(section);
172
- if (hasFolding) {
173
- tokens.push(openSection());
174
- sections.push(section);
175
- }
176
- }
177
- tokens.push(token);
178
- if (token.type === TokenType.HeadingClose && hasFolding) {
179
- tokens.push(openContent());
180
- }
181
- }
182
- closeAllSections();
183
- if (state.tokens.length !== tokens.length) {
184
- state.env ??= {};
185
- state.env[ENV_FLAG_NAME] = true;
186
- }
187
- state.tokens = tokens;
188
- function openSection() {
189
- const t = new Token(TokenType.SectionOpen, "section", 1);
190
- t.attrPush(["class", SectionCN.Section]);
191
- t.attrPush([SectionAttr.DataKey, DATA_KEY]);
192
- t.attrPush([SectionAttr.DataId, generateID()]);
193
- t.block = true;
194
- return t;
195
- }
196
- function closeSection() {
197
- const t = new Token(TokenType.SectionClose, "section", -1);
198
- t.block = true;
199
- return t;
200
- }
201
- function openContent() {
202
- const t = new Token(TokenType.ContentOpen, "div", 1);
203
- t.attrPush(["class", SectionCN.Content]);
204
- t.block = true;
205
- return t;
206
- }
207
- function closeContent() {
208
- const t = new Token(TokenType.ContentClose, "div", -1);
209
- t.block = true;
210
- return t;
211
- }
212
- function closeSections(section) {
213
- while (last(sections) && section.header <= last(sections).header && section.nesting <= last(sections).nesting) {
214
- sections.pop();
215
- tokens.push(closeContent());
216
- tokens.push(closeSection());
217
- }
218
- }
219
- function closeSectionsToCurrentNesting(nesting) {
220
- while (last(sections) && nesting < last(sections).nesting) {
221
- sections.pop();
222
- tokens.push(closeContent());
223
- tokens.push(closeSection());
224
- }
225
- }
226
- function closeAllSections() {
227
- while (sections.pop()) {
228
- tokens.push(closeContent());
229
- tokens.push(closeSection());
230
- }
231
- }
232
- };
233
-
234
- // src/plugin/plugin.ts
235
- var foldingHeadingPlugin = (md) => {
236
- md.block.ruler.at("heading", headingBlockRule, { alt: ["paragraph", "reference", "blockquote"] });
237
- md.core.ruler.push("heading_sections", sectionsCoreRule);
238
- };
239
-
240
- // src/plugin/transform.ts
241
- var registerTransform = (md, {
242
- runtime,
243
- bundle,
244
- output
245
- }) => {
246
- md.use(foldingHeadingPlugin);
247
- md.core.ruler.push("heading_sections_after", ({ env }) => {
248
- hidden(env, "bundled", /* @__PURE__ */ new Set());
249
- if (env?.[ENV_FLAG_NAME]) {
250
- env.meta = env.meta || {};
251
- env.meta.script = env.meta.script || [];
252
- env.meta.script.push(runtime.script);
253
- env.meta.style = env.meta.style || [];
254
- env.meta.style.push(runtime.style);
255
- if (bundle) {
256
- copyRuntime({ runtime, output }, env.bundled);
257
- }
258
- }
259
- });
260
- };
261
- function transform(options = {}) {
262
- const { bundle = true } = options;
263
- if (bundle && typeof options.runtime === "string") {
264
- throw new TypeError("Option `runtime` should be record when `bundle` is enabled.");
265
- }
266
- const runtime = typeof options.runtime === "string" ? { script: options.runtime, style: options.runtime } : options.runtime || {
267
- script: "_assets/folding-headings-extension.js",
268
- style: "_assets/folding-headings-extension.css"
269
- };
270
- const plugin = function(md, { output = "." } = {}) {
271
- registerTransform(md, {
272
- runtime,
273
- bundle,
274
- output
275
- });
276
- };
277
- Object.assign(plugin, {
278
- collect(input, { destRoot = "." }) {
279
- const MdIt = dynrequire("markdown-it");
280
- const md = new MdIt().use((md2) => {
281
- registerTransform(md2, {
282
- runtime,
283
- bundle,
284
- output: destRoot
285
- });
286
- });
287
- md.parse(input, {});
288
- }
289
- });
290
- return plugin;
291
- }
292
- // Annotate the CommonJS export names for ESM import in node:
293
- 0 && (module.exports = {
294
- TokenType,
295
- transform
296
- });
297
- //# sourceMappingURL=index.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/plugin/index.ts", "../../src/common/const.ts", "../../src/plugin/const.ts", "../../src/plugin/headingBlockRule.ts", "../../src/plugin/utils.ts", "../../src/plugin/sectionsCoreRule.ts", "../../src/plugin/plugin.ts", "../../src/plugin/transform.ts"],
4
- "sourcesContent": ["export type {TransformOptions} from './transform';\nexport {transform} from './transform';\nexport {TokenType} from './const';\n", "export const DATA_KEY = 'heading-section';\n\nexport const SectionAttr = {\n DataId: 'data-diplodoc-id',\n DataKey: 'data-diplodoc-key',\n} as const;\n\nexport const SectionCN = {\n Section: 'heading-section',\n Content: 'heading-section-content',\n};\n", "export {SectionCN, DATA_KEY, SectionAttr} from '../common/const';\n\nexport const ENV_FLAG_NAME = 'has-folding-headings';\n\nexport const TokenType = {\n Heading: 'heading',\n HeadingOpen: 'heading_open',\n HeadingClose: 'heading_close',\n Section: 'heading_section',\n SectionOpen: 'heading_section_open',\n SectionClose: 'heading_section_close',\n Content: 'heading_section_content',\n ContentOpen: 'heading_section_content_open',\n ContentClose: 'heading_section_content_close',\n} as const;\n", "import type ParserBlock from 'markdown-it/lib/parser_block';\n\nimport {TokenType} from './const';\n\n// copied from https://github.com/markdown-it/markdown-it/blob/14.1.0/lib/rules_block/heading.mjs\n// modified: support syntax ###+ for folding headings\nexport const headingBlockRule: ParserBlock.RuleBlock = (state, startLine, _endLine, silent) => {\n const {isSpace} = state.md.utils;\n\n let pos = state.bMarks[startLine] + state.tShift[startLine];\n let max = state.eMarks[startLine];\n\n // if it's indented more than 3 spaces, it should be a code block\n if (state.sCount[startLine] - state.blkIndent >= 4) {\n return false;\n }\n\n let ch = state.src.charCodeAt(pos);\n\n if (ch !== 0x23 /* # */ || pos >= max) {\n return false;\n }\n\n // count heading level\n let level = 1;\n ch = state.src.charCodeAt(++pos);\n while (ch === 0x23 /* # */ && pos < max && level <= 6) {\n level++;\n ch = state.src.charCodeAt(++pos);\n }\n\n let folding = false;\n if (ch === 0x2b /* + */) {\n folding = true;\n ch = state.src.charCodeAt(++pos);\n }\n\n if (level > 6 || (pos < max && !isSpace(ch))) {\n return false;\n }\n\n if (silent) {\n return true;\n }\n\n // Let's cut tails like ' ### ' from the end of string\n\n max = state.skipSpacesBack(max, pos);\n const tmp = state.skipCharsBack(max, 0x23, pos); // #\n if (tmp > pos && isSpace(state.src.charCodeAt(tmp - 1))) {\n max = tmp;\n }\n\n state.line = startLine + 1;\n\n let token = state.push(TokenType.HeadingOpen, 'h' + String(level), 1);\n token.markup = '########'.slice(0, level) + (folding ? '+' : '');\n token.map = [startLine, state.line];\n if (folding) {\n token.meta ||= {};\n token.meta.folding = true;\n }\n\n token = state.push('inline', '', 0);\n token.content = state.src.slice(pos, max).trim();\n token.map = [startLine, state.line];\n token.children = [];\n\n token = state.push(TokenType.HeadingClose, 'h' + String(level), -1);\n token.markup = '########'.slice(0, level) + (folding ? '+' : '');\n if (folding) {\n token.meta ||= {};\n token.meta.folding = true;\n }\n\n return true;\n};\n", "import {DATA_KEY} from './const';\n\nexport function generateID() {\n return DATA_KEY + '-' + Math.random().toString(36).substr(2, 8);\n}\n\nexport function headingLevel(header: string) {\n return parseInt(header.charAt(1), 10);\n}\n\nexport function last<T>(arr: T[]): T | undefined {\n return arr[arr.length - 1];\n}\n\nexport function hidden<B extends Record<string | symbol, unknown>, F extends string | symbol, V>(\n box: B,\n field: F,\n value: V,\n) {\n if (!(field in box)) {\n Object.defineProperty(box, field, {\n enumerable: false,\n value: value,\n });\n }\n\n return box as B & {[P in F]: V};\n}\n\nexport type Runtime = {\n script: string;\n style: string;\n};\n\ndeclare const __dirname: string;\nexport function copyRuntime(\n {runtime, output}: {runtime: Runtime; output: string},\n cache: Set<string>,\n) {\n const PATH_TO_RUNTIME = '../runtime';\n const {join, resolve} = dynrequire('node:path');\n const runtimeFiles = {\n 'index.js': runtime.script,\n 'index.css': runtime.style,\n };\n for (const [originFile, outputFile] of Object.entries(runtimeFiles)) {\n const file = join(PATH_TO_RUNTIME, originFile);\n if (!cache.has(file)) {\n cache.add(file);\n copy(resolve(__dirname, file), join(output, outputFile));\n }\n }\n}\n\nexport function copy(from: string, to: string) {\n const {mkdirSync, copyFileSync} = dynrequire('node:fs');\n const {dirname} = dynrequire('node:path');\n\n mkdirSync(dirname(to), {recursive: true});\n copyFileSync(from, to);\n}\n\n/*\n * Runtime require hidden for builders.\n * Used for nodejs api\n */\nexport function dynrequire(module: string) {\n return eval(`require('${module}')`);\n}\n", "import type Core from 'markdown-it/lib/parser_core';\n\nimport {DATA_KEY, ENV_FLAG_NAME, SectionAttr, SectionCN, TokenType} from './const';\nimport {generateID, headingLevel, last} from './utils';\n\ntype Section = {header: number; nesting: number};\n\nexport const sectionsCoreRule: Core.RuleCore = (state) => {\n const Token = state.Token;\n const tokens: typeof state.tokens = []; // output\n const sections: Section[] = [];\n let nestedLevel = 0;\n\n for (const token of state.tokens) {\n // record level of nesting\n if (token.type.search(TokenType.Heading) !== 0) {\n nestedLevel += token.nesting;\n }\n if (last(sections) && nestedLevel < last(sections)!.nesting) {\n closeSectionsToCurrentNesting(nestedLevel);\n }\n\n const hasFolding = token.markup.endsWith('#+');\n\n // add sections before headers\n if (token.type === TokenType.HeadingOpen) {\n const section: Section = {\n header: headingLevel(token.tag),\n nesting: nestedLevel,\n };\n closeSections(section);\n if (hasFolding) {\n tokens.push(openSection());\n sections.push(section);\n }\n }\n\n tokens.push(token);\n\n if (token.type === TokenType.HeadingClose && hasFolding) {\n tokens.push(openContent());\n }\n }\n\n // end for every token\n closeAllSections();\n\n if (state.tokens.length !== tokens.length) {\n state.env ??= {};\n state.env[ENV_FLAG_NAME] = true;\n }\n\n state.tokens = tokens;\n\n function openSection() {\n const t = new Token(TokenType.SectionOpen, 'section', 1);\n t.attrPush(['class', SectionCN.Section]);\n t.attrPush([SectionAttr.DataKey, DATA_KEY]);\n t.attrPush([SectionAttr.DataId, generateID()]);\n t.block = true;\n return t;\n }\n\n function closeSection() {\n const t = new Token(TokenType.SectionClose, 'section', -1);\n t.block = true;\n return t;\n }\n\n function openContent() {\n const t = new Token(TokenType.ContentOpen, 'div', 1);\n t.attrPush(['class', SectionCN.Content]);\n t.block = true;\n return t;\n }\n\n function closeContent() {\n const t = new Token(TokenType.ContentClose, 'div', -1);\n t.block = true;\n return t;\n }\n\n function closeSections(section: Section) {\n while (\n last(sections) &&\n section.header <= last(sections)!.header &&\n section.nesting <= last(sections)!.nesting\n ) {\n sections.pop();\n tokens.push(closeContent());\n tokens.push(closeSection());\n }\n }\n\n function closeSectionsToCurrentNesting(nesting: number) {\n while (last(sections) && nesting < last(sections)!.nesting) {\n sections.pop();\n tokens.push(closeContent());\n tokens.push(closeSection());\n }\n }\n\n function closeAllSections() {\n while (sections.pop()) {\n tokens.push(closeContent());\n tokens.push(closeSection());\n }\n }\n};\n", "import type {PluginSimple} from 'markdown-it';\n\nimport {headingBlockRule} from './headingBlockRule';\nimport {sectionsCoreRule} from './sectionsCoreRule';\n\nexport const foldingHeadingPlugin: PluginSimple = (md) => {\n md.block.ruler.at('heading', headingBlockRule, {alt: ['paragraph', 'reference', 'blockquote']});\n md.core.ruler.push('heading_sections', sectionsCoreRule);\n};\n", "import type MarkdownIt from 'markdown-it';\nimport {PluginWithOptions} from 'markdown-it';\n\nimport {ENV_FLAG_NAME} from './const';\nimport {foldingHeadingPlugin} from './plugin';\nimport {type Runtime, copyRuntime, dynrequire, hidden} from './utils';\n\nconst registerTransform = (\n md: MarkdownIt,\n {\n runtime,\n bundle,\n output,\n }: Pick<NormalizedPluginOptions, 'bundle' | 'runtime'> & {\n output: string;\n },\n) => {\n md.use(foldingHeadingPlugin);\n md.core.ruler.push('heading_sections_after', ({env}) => {\n hidden(env, 'bundled', new Set<string>());\n\n if (env?.[ENV_FLAG_NAME]) {\n env.meta = env.meta || {};\n env.meta.script = env.meta.script || [];\n env.meta.script.push(runtime.script);\n env.meta.style = env.meta.style || [];\n env.meta.style.push(runtime.style);\n\n if (bundle) {\n copyRuntime({runtime, output}, env.bundled);\n }\n }\n });\n};\n\ntype NormalizedPluginOptions = Omit<TransformOptions, 'runtime'> & {\n runtime: Runtime;\n};\n\nexport type TransformOptions = {\n runtime?:\n | string\n | {\n script: string;\n style: string;\n };\n bundle?: boolean;\n};\n\ntype InputOptions = {\n destRoot: string;\n};\n\nexport function transform(options: Partial<TransformOptions> = {}) {\n const {bundle = true} = options;\n\n if (bundle && typeof options.runtime === 'string') {\n throw new TypeError('Option `runtime` should be record when `bundle` is enabled.');\n }\n\n const runtime: Runtime =\n typeof options.runtime === 'string'\n ? {script: options.runtime, style: options.runtime}\n : options.runtime || {\n script: '_assets/folding-headings-extension.js',\n style: '_assets/folding-headings-extension.css',\n };\n\n const plugin: PluginWithOptions<{output?: string}> = function (\n md: MarkdownIt,\n {output = '.'} = {},\n ) {\n registerTransform(md, {\n runtime,\n bundle,\n output,\n });\n };\n\n Object.assign(plugin, {\n collect(input: string, {destRoot = '.'}: InputOptions) {\n const MdIt = dynrequire('markdown-it');\n const md = new MdIt().use((md: MarkdownIt) => {\n registerTransform(md, {\n runtime,\n bundle,\n output: destRoot,\n });\n });\n\n md.parse(input, {});\n },\n });\n\n return plugin;\n}\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,WAAW;AAEjB,IAAM,cAAc;AAAA,EACvB,QAAQ;AAAA,EACR,SAAS;AACb;AAEO,IAAM,YAAY;AAAA,EACrB,SAAS;AAAA,EACT,SAAS;AACb;;;ACRO,IAAM,gBAAgB;AAEtB,IAAM,YAAY;AAAA,EACrB,SAAS;AAAA,EACT,aAAa;AAAA,EACb,cAAc;AAAA,EACd,S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AAkB,IAAI;AAAA,MAClB;AAAA,MACA;AAAA,MACA;AAAA,IACJ,CAAC;AAAA,EACL;AAEA,SAAO,OAAO,QAAQ;AAAA,IAClB,QAAQ,OAAe,EAAC,WAAW,IAAG,GAAiB;AACnD,YAAM,OAAO,WAAW,aAAa;AACrC,YAAM,KAAK,IAAI,KAAK,EAAE,IAAI,CAACA,QAAmB;AAC1C,0BAAkBA,KAAI;AAAA,UAClB;AAAA,UACA;AAAA,UACA,QAAQ;AAAA,QACZ,CAAC;AAAA,MACL,CAAC;AAED,SAAG,MAAM,OAAO,CAAC,CAAC;AAAA,IACtB;AAAA,EACJ,CAAC;AAED,SAAO;AACX;",
6
- "names": ["md"]
7
- }
@@ -1,2 +0,0 @@
1
- import type { PluginSimple } from 'markdown-it';
2
- export declare const foldingHeadingPlugin: PluginSimple;
@@ -1,2 +0,0 @@
1
- import type Core from 'markdown-it/lib/parser_core';
2
- export declare const sectionsCoreRule: Core.RuleCore;
@@ -1,11 +0,0 @@
1
- import type MarkdownIt from 'markdown-it';
2
- export type TransformOptions = {
3
- runtime?: string | {
4
- script: string;
5
- style: string;
6
- };
7
- bundle?: boolean;
8
- };
9
- export declare function transform(options?: Partial<TransformOptions>): MarkdownIt.PluginWithOptions<{
10
- output?: string;
11
- }>;
@@ -1,14 +0,0 @@
1
- export declare function generateID(): string;
2
- export declare function headingLevel(header: string): number;
3
- export declare function last<T>(arr: T[]): T | undefined;
4
- export declare function hidden<B extends Record<string | symbol, unknown>, F extends string | symbol, V>(box: B, field: F, value: V): B & { [P in F]: V; };
5
- export type Runtime = {
6
- script: string;
7
- style: string;
8
- };
9
- export declare function copyRuntime({ runtime, output }: {
10
- runtime: Runtime;
11
- output: string;
12
- }, cache: Set<string>): void;
13
- export declare function copy(from: string, to: string): void;
14
- export declare function dynrequire(module: string): any;
@@ -1,10 +0,0 @@
1
- export { SectionAttr, DATA_KEY } from '../common/const';
2
- export declare const GLOBAL_KEY = "heading_sections";
3
- export declare const Selector: {
4
- readonly Heading: ".yfm .heading-section > h1,h2,h3,h4,h5,h6";
5
- readonly Section: ".yfm .heading-section";
6
- readonly Content: ".yfm .heading-section-content";
7
- };
8
- export declare const ClassName: {
9
- readonly Open: "open";
10
- };
@@ -1,13 +0,0 @@
1
- export declare class HeadingSectionContoller {
2
- private __doc;
3
- constructor(doc: Document);
4
- open(id: string): void;
5
- toggle(id: string): void;
6
- close(id: string): void;
7
- destroy(): void;
8
- private _findSections;
9
- private _onDocClick;
10
- private _findHeading;
11
- private _matchHeading;
12
- private _toogleSection;
13
- }
@@ -1,2 +0,0 @@
1
- .yfm h1[data-folded],.yfm h2[data-folded],.yfm h3[data-folded],.yfm h4[data-folded],.yfm h5[data-folded],.yfm h6[data-folded]{position:relative;padding-left:28px}.yfm h1[data-folded]:before,.yfm h2[data-folded]:before,.yfm h3[data-folded]:before,.yfm h4[data-folded]:before,.yfm h5[data-folded]:before,.yfm h6[data-folded]:before{position:absolute;z-index:1;top:50%;left:0;content:"";cursor:pointer;background-color:currentColor;mask-image:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16"><path fill="currentColor" fill-rule="evenodd" d="M2.97 5.47a.75.75 0 0 1 1.06 0L8 9.44l3.97-3.97a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 0 1 0-1.06" clip-rule="evenodd"/></svg>');mask-repeat:no-repeat;mask-position:center;transition:transform .3s ease;transform:translateY(-50%) rotate(-90deg)}.yfm h1[data-folded]:before{width:28px;height:28px;mask-size:20px}.yfm h2[data-folded]:before,.yfm h3[data-folded]:before{left:2px;width:24px;height:24px;mask-size:20px}.yfm h4[data-folded]:before{left:6px;width:20px;height:20px;mask-size:16px}.yfm h5[data-folded]:before{left:8px;width:20px;height:20px;mask-size:14px}.yfm h6[data-folded]:before{left:8px;width:20px;height:20px;mask-size:12px}.yfm h1[data-folded=false]:before,.yfm h2[data-folded=false]:before,.yfm h3[data-folded=false]:before,.yfm h4[data-folded=false]:before,.yfm h5[data-folded=false]:before,.yfm h6[data-folded=false]:before{transform:translateY(-50%)}.heading-section-content{display:none;padding-left:28px;overflow:hidden;transition:height .3s ease-in-out}.heading-section-content>.heading-section{margin-left:-28px}.heading-section>h1,.heading-section>h2,.heading-section>h3,.heading-section>h4,.heading-section>h5,.heading-section>h6{cursor:pointer;position:relative;padding-left:28px}.heading-section>h1:before,.heading-section>h2:before,.heading-section>h3:before,.heading-section>h4:before,.heading-section>h5:before,.heading-section>h6:before{position:absolute;z-index:1;top:50%;left:0;content:"";cursor:pointer;background-color:currentColor;mask-image:url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="none" viewBox="0 0 16 16"><path fill="currentColor" fill-rule="evenodd" d="M2.97 5.47a.75.75 0 0 1 1.06 0L8 9.44l3.97-3.97a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 0 1 0-1.06" clip-rule="evenodd"/></svg>');mask-repeat:no-repeat;mask-position:center;transition:transform .3s ease;transform:translateY(-50%) rotate(-90deg)}.heading-section>h1 .yfm-anchor,.heading-section>h2 .yfm-anchor,.heading-section>h3 .yfm-anchor,.heading-section>h4 .yfm-anchor,.heading-section>h5 .yfm-anchor,.heading-section>h6 .yfm-anchor{margin-left:-52px}.heading-section>h1:before{width:28px;height:28px;mask-size:20px}.heading-section>h2:before,.heading-section>h3:before{left:2px;width:24px;height:24px;mask-size:20px}.heading-section>h4:before{left:6px;width:20px;height:20px;mask-size:16px}.heading-section>h5:before{left:8px;width:20px;height:20px;mask-size:14px}.heading-section>h6:before{left:8px;width:20px;height:20px;mask-size:12px}.heading-section.open>.heading-section-content{display:revert}.heading-section.open>h1:before,.heading-section.open>h2:before,.heading-section.open>h3:before,.heading-section.open>h4:before,.heading-section.open>h5:before,.heading-section.open>h6:before{transform:translateY(-50%)}
2
- /*# sourceMappingURL=index.css.map */
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/runtime/styles/_editor.scss", "../../src/runtime/styles/_mixins.scss", "../../src/runtime/styles/index.scss"],
4
- "sourcesContent": ["// this styles for folding headings in markdown editor\n\n@use './mixins' as m;\n\n.yfm {\n h1[data-folded],\n h2[data-folded],\n h3[data-folded],\n h4[data-folded],\n h5[data-folded],\n h6[data-folded] {\n @include m.chevron();\n }\n\n h1[data-folded] {\n @include m.chevron_size_xl();\n }\n\n h2[data-folded],\n h3[data-folded] {\n @include m.chevron_size_l();\n }\n\n h4[data-folded] {\n @include m.chevron_size_m();\n }\n\n h5[data-folded] {\n @include m.chevron_size_s();\n }\n\n h6[data-folded] {\n @include m.chevron_size_xs();\n }\n\n h1[data-folded=false],\n h2[data-folded=false],\n h3[data-folded=false],\n h4[data-folded=false],\n h5[data-folded=false],\n h6[data-folded=false] {\n @include m.chevron_open();\n }\n}\n", "$chevronIcon: url('data:image/svg+xml;utf8,<svg xmlns=\"http://www.w3.org/2000/svg\" width=\"16\" height=\"16\" fill=\"none\" viewBox=\"0 0 16 16\"><path fill=\"currentColor\" fill-rule=\"evenodd\" d=\"M2.97 5.47a.75.75 0 0 1 1.06 0L8 9.44l3.97-3.97a.75.75 0 1 1 1.06 1.06l-4.5 4.5a.75.75 0 0 1-1.06 0l-4.5-4.5a.75.75 0 0 1 0-1.06\" clip-rule=\"evenodd\"/></svg>');\n\n@mixin chevron() {\n position: relative;\n\n padding-left: 28px;\n\n &::before {\n position: absolute;\n z-index: 1;\n top: 50%;\n left: 0;\n\n content: '';\n cursor: pointer;\n\n background-color: currentColor;\n mask-image: $chevronIcon;\n mask-repeat: no-repeat;\n mask-position: center;\n\n transition: transform 0.3s ease;\n transform: translateY(-50%) rotate(-90deg);\n }\n}\n\n@mixin chevron_size_xs() {\n &::before {\n left: 8px;\n\n width: 20px;\n height: 20px;\n\n mask-size: 12px;\n }\n}\n\n@mixin chevron_size_s() {\n &::before {\n left: 8px;\n\n width: 20px;\n height: 20px;\n\n mask-size: 14px;\n }\n}\n\n@mixin chevron_size_m() {\n &::before {\n left: 6px;\n\n width: 20px;\n height: 20px;\n\n mask-size: 16px;\n }\n}\n\n@mixin chevron_size_l() {\n &::before {\n left: 2px;\n\n width: 24px;\n height: 24px;\n\n mask-size: 20px;\n }\n}\n\n@mixin chevron_size_xl() {\n &::before {\n width: 28px;\n height: 28px;\n\n mask-size: 20px;\n }\n}\n\n@mixin chevron_open() {\n &::before {\n transform: translateY(-50%);\n }\n}\n", "@use './mixins' as m;\n@use './editor';\n\n$paddingLeft: 28px;\n$yfmAnchorWidth: 24px;\n\n.heading-section {\n $class: &;\n\n &-content {\n display: none;\n padding-left: $paddingLeft;\n overflow: hidden;\n transition: height 0.3s ease-in-out;\n\n & > #{$class} {\n margin-left: -#{$paddingLeft};\n }\n }\n\n > h1,\n > h2,\n > h3,\n > h4,\n > h5,\n > h6 {\n cursor: pointer;\n\n @include m.chevron();\n\n .yfm-anchor {\n margin-left: -#{$yfmAnchorWidth + $paddingLeft}; // width of yfm-anchor (24px) + padding of heading (28px)\n }\n }\n\n > h1 {\n @include m.chevron_size_xl();\n }\n\n > h2,\n > h3 {\n @include m.chevron_size_l();\n }\n\n > h4 {\n @include m.chevron_size_m();\n }\n\n > h5 {\n @include m.chevron_size_s();\n }\n\n > h6 {\n @include m.chevron_size_xs();\n }\n\n &.open {\n > #{$class}-content {\n display: revert;\n }\n\n > h1,\n > h2,\n > h3,\n > h4,\n > h5,\n > h6 {\n @include m.chevron_open();\n }\n }\n}\n"],
5
- "mappings": "AAKI,CAAA,IAAA,EAAA,CAAA,aAAA,CAAA,IAAA,EAAA,CAAA,aAAA,CAAA,IAAA,EAAA,CAAA,aAAA,CAAA,IAAA,EAAA,CAAA,aAAA,CAAA,IAAA,EAAA,CAAA,aAAA,CAAA,IAAA,EAAA,CAAA,aCFA,SAAA,SAEA,aAAA,KAEA,CDFA,ICEA,EAAA,CAAA,YAAA,QA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DuBJ,CAAA,EAAA,QAAA,CCjEI,eDiEJ,CCvBI,IDuBJ,CAAA,EAAA,QAAA,CCjEI,eDiEJ,CCvBI,IDuBJ,CAAA,EAAA,QAAA,CCjEI,eDiEJ,CCvBI,IDuBJ,CAAA,EAAA,QAAA,CCjEI,eDiEJ,CCvBI,IDuBJ,CAAA,EAAA,QAAA,CCjEI,eDiEJ,CCvBI,IDuBJ,CAAA,EAAA,QACI,UAAA,WAAA",
6
- "names": []
7
- }
@@ -1,8 +0,0 @@
1
- import { GLOBAL_KEY } from './const';
2
- import { HeadingSectionContoller } from './controller';
3
- import './styles/index.scss';
4
- declare global {
5
- interface Window {
6
- [GLOBAL_KEY]: HeadingSectionContoller;
7
- }
8
- }
@@ -1,2 +0,0 @@
1
- "use strict";(()=>{var n="heading-section",i={DataId:"data-diplodoc-id",DataKey:"data-diplodoc-key"};var a="heading_sections",c={Heading:".yfm .heading-section > h1,h2,h3,h4,h5,h6",Section:".yfm .heading-section",Content:".yfm .heading-section-content"},o={Open:"open"};var A=t=>{let e=t.composedPath();return Array.isArray(e)&&e.length>0?e[0]:t.target},C=t=>{let e=A(t);return!e||!e.matches};var I=class{__doc;constructor(e){this.__doc=e,this.__doc.addEventListener("click",this._onDocClick)}open(e){for(let g of this._findSections(e))g.classList.add(o.Open)}toggle(e){for(let g of this._findSections(e))g.classList.toggle(o.Open)}close(e){for(let g of this._findSections(e))g.classList.remove(o.Open)}destroy(){this.__doc.removeEventListener("click",this._onDocClick)}_findSections(e){return Array.from(this.__doc.querySelectorAll(`section[${i.DataKey}=${n}][${i.DataId}=${e}]`))}_onDocClick=e=>{if(C(e))return;let g=this._findHeading(e);g&&this._toogleSection(g)};_findHeading(e){let g=A(e);return this._matchHeading(g)?g:e.composedPath?.()?.find(this._matchHeading)}_matchHeading=e=>e instanceof HTMLElement?e?.matches?.(c.Heading)&&e.parentElement?.matches(c.Section):!1;_toogleSection(e){let g=e.parentElement;g instanceof HTMLElement&&g.classList.toggle(o.Open)}};typeof window<"u"&&typeof document<"u"&&!window[a]&&(window[a]=new I(document));})();
2
- //# sourceMappingURL=index.js.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../src/common/const.ts", "../../src/runtime/const.ts", "../../src/runtime/utils.ts", "../../src/runtime/controller.ts", "../../src/runtime/index.ts"],
4
- "sourcesContent": ["export const DATA_KEY = 'heading-section';\n\nexport const SectionAttr = {\n DataId: 'data-diplodoc-id',\n DataKey: 'data-diplodoc-key',\n} as const;\n\nexport const SectionCN = {\n Section: 'heading-section',\n Content: 'heading-section-content',\n};\n", "export {SectionAttr, DATA_KEY} from '../common/const';\n\nexport const GLOBAL_KEY = 'heading_sections';\n\nexport const Selector = {\n Heading: '.yfm .heading-section > h1,h2,h3,h4,h5,h6',\n Section: '.yfm .heading-section',\n Content: '.yfm .heading-section-content',\n} as const;\n\nexport const ClassName = {\n Open: 'open',\n} as const;\n", "export const getEventTarget = (event: Event) => {\n const path = event.composedPath();\n return Array.isArray(path) && path.length > 0 ? path[0] : event.target;\n};\n\nexport const isCustom = (event: Event) => {\n const target = getEventTarget(event);\n return !target || !(target as HTMLElement).matches;\n};\n", "import {ClassName, DATA_KEY, SectionAttr, Selector} from './const';\nimport {getEventTarget, isCustom} from './utils';\n\nexport class HeadingSectionContoller {\n private __doc: Document;\n\n constructor(doc: Document) {\n this.__doc = doc;\n this.__doc.addEventListener('click', this._onDocClick);\n }\n\n open(id: string) {\n for (const elem of this._findSections(id)) {\n elem.classList.add(ClassName.Open);\n }\n }\n\n toggle(id: string) {\n for (const elem of this._findSections(id)) {\n elem.classList.toggle(ClassName.Open);\n }\n }\n\n close(id: string) {\n for (const elem of this._findSections(id)) {\n elem.classList.remove(ClassName.Open);\n }\n }\n\n destroy() {\n this.__doc.removeEventListener('click', this._onDocClick);\n }\n\n private _findSections(id: string) {\n return Array.from(\n this.__doc.querySelectorAll(\n `section[${SectionAttr.DataKey}=${DATA_KEY}][${SectionAttr.DataId}=${id}]`,\n ),\n );\n }\n\n private _onDocClick = (event: MouseEvent) => {\n if (isCustom(event)) return;\n\n const heading = this._findHeading(event);\n if (heading) this._toogleSection(heading);\n };\n\n private _findHeading(event: MouseEvent): HTMLElement | undefined {\n const target = getEventTarget(event);\n\n if (this._matchHeading(target)) return target as HTMLElement;\n\n const path = event.composedPath?.();\n return path?.find(this._matchHeading) as HTMLElement | undefined;\n }\n\n private _matchHeading = (target: EventTarget | null) => {\n if (!(target instanceof HTMLElement)) return false;\n\n return (\n target?.matches?.(Selector.Heading) && target.parentElement?.matches(Selector.Section)\n );\n };\n\n private _toogleSection(heading: HTMLElement) {\n const section = heading.parentElement;\n if (section instanceof HTMLElement) {\n section.classList.toggle(ClassName.Open);\n }\n }\n}\n", "import {GLOBAL_KEY} from './const';\nimport {HeadingSectionContoller} from './controller';\n\nimport './styles/index.scss';\n\nif (typeof window !== 'undefined' && typeof document !== 'undefined' && !window[GLOBAL_KEY]) {\n window[GLOBAL_KEY] = new HeadingSectionContoller(document);\n}\n\ndeclare global {\n interface Window {\n [GLOBAL_KEY]: HeadingSectionContoller;\n }\n}\n"],
5
- "mappings": "mBAAO,IAAMA,EAAW,kBAEXC,EAAc,CACvB,OAAQ,mBACR,QAAS,mBACb,ECHO,IAAMC,EAAa,mBAEbC,EAAW,CACpB,QAAS,4CACT,QAAS,wBACT,QAAS,+BACb,EAEaC,EAAY,CACrB,KAAM,MACV,ECZO,IAAMC,EAAkBC,GAAiB,CAC5C,IAAMC,EAAOD,EAAM,aAAa,EAChC,OAAO,MAAM,QAAQC,CAAI,GAAKA,EAAK,OAAS,EAAIA,EAAK,CAAC,EAAID,EAAM,MACpE,EAEaE,EAAYF,GAAiB,CACtC,IAAMG,EAASJ,EAAeC,CAAK,EACnC,MAAO,CAACG,GAAU,CAAEA,EAAuB,OAC/C,ECLO,IAAMC,EAAN,KAA8B,CACzB,MAER,YAAYC,EAAe,CACvB,KAAK,MAAQA,EACb,KAAK,MAAM,iBAAiB,QAAS,KAAK,WA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adingSectionContoller", "doc", "id", "elem", "ClassName", "SectionAttr", "DATA_KEY", "event", "isCustom", "heading", "target", "getEventTarget", "Selector", "section", "GLOBAL_KEY", "HeadingSectionContoller"]
7
- }
@@ -1,2 +0,0 @@
1
- export declare const getEventTarget: (event: Event) => EventTarget | null;
2
- export declare const isCustom: (event: Event) => boolean;