@diplodoc/client 3.10.0 → 3.10.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.
@@ -12411,12 +12411,25 @@ function getPageType({
12411
12411
 
12412
12412
 
12413
12413
  }),
12414
- 14060: (function (module, __unused_webpack_exports, __webpack_require__) {
12414
+ 20535: (function (__unused_webpack_module, __webpack_exports__, __webpack_require__) {
12415
+ "use strict";
12416
+ __webpack_require__.d(__webpack_exports__, {
12417
+ q: () => (f)
12418
+ });
12419
+ /* ESM import */var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(67294);
12420
+ var t="yfm_cut";var f=(o={})=>((0,react__WEBPACK_IMPORTED_MODULE_0__.useEffect)(()=>{window[t].focusActiveCut(o)}),!1);
12421
+ //# sourceMappingURL=index.js.map
12422
+
12423
+
12424
+ }),
12425
+ 86224: (function (module, __unused_webpack_exports, __webpack_require__) {
12415
12426
  "use strict";
12416
12427
 
12428
+ var __create = Object.create;
12417
12429
  var __defProp = Object.defineProperty;
12418
12430
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12419
12431
  var __getOwnPropNames = Object.getOwnPropertyNames;
12432
+ var __getProtoOf = Object.getPrototypeOf;
12420
12433
  var __hasOwnProp = Object.prototype.hasOwnProperty;
12421
12434
  var __export = (target, all) => {
12422
12435
  for (var name in all)
@@ -12430,393 +12443,113 @@ var __copyProps = (to, from, except, desc) => {
12430
12443
  }
12431
12444
  return to;
12432
12445
  };
12446
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
12447
+ // If the importer is in node compatibility mode or this is not an ESM
12448
+ // file that has been converted to a CommonJS file using a Babel-
12449
+ // compatible transform (i.e. "__esModule" has not been set), then set
12450
+ // "default" to the CommonJS "module.exports" for node compatibility.
12451
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
12452
+ mod
12453
+ ));
12433
12454
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
12434
12455
 
12435
- // src/plugin/index.ts
12436
- var plugin_exports = {};
12437
- __export(plugin_exports, {
12438
- TokenType: () => TokenType,
12439
- transform: () => transform
12456
+ // src/index.ts
12457
+ var src_exports = {};
12458
+ __export(src_exports, {
12459
+ createBlockInlineToken: () => createBlockInlineToken,
12460
+ directiveParser: () => directiveParser,
12461
+ disableBlockDirectives: () => disableBlockDirectives,
12462
+ disableInlineDirectives: () => disableInlineDirectives,
12463
+ enableBlockDirectives: () => enableBlockDirectives,
12464
+ enableInlineDirectives: () => enableInlineDirectives,
12465
+ registerContainerDirective: () => registerContainerDirective,
12466
+ registerInlineDirective: () => registerInlineDirective,
12467
+ registerLeafBlockDirective: () => registerLeafBlockDirective,
12468
+ tokenizeBlockContent: () => tokenizeBlockContent,
12469
+ tokenizeInlineContent: () => tokenizeInlineContent
12440
12470
  });
12441
- module.exports = __toCommonJS(plugin_exports);
12442
-
12443
- // src/plugin/plugin.ts
12444
- var import_utils = __webpack_require__(87910);
12471
+ module.exports = __toCommonJS(src_exports);
12472
+ var import_markdown_it_directive = __toESM(__webpack_require__(20767));
12445
12473
 
12446
- // src/plugin/const.ts
12447
- var ENV_FLAG_NAME = "has-yfm-cut";
12448
- var TokenType = {
12449
- Cut: "yfm_cut",
12450
- CutOpen: "yfm_cut_open",
12451
- CutClose: "yfm_cut_close",
12452
- Title: "yfm_cut_title",
12453
- TitleOpen: "yfm_cut_title_open",
12454
- TitleClose: "yfm_cut_title_close",
12455
- Content: "yfm_cut_content",
12456
- ContentOpen: "yfm_cut_content_open",
12457
- ContentClose: "yfm_cut_content_close"
12458
- };
12459
- var ClassNames = {
12460
- Cut: "yfm-cut",
12461
- Title: "yfm-cut-title",
12462
- Content: "yfm-cut-content"
12474
+ // src/const.ts
12475
+ var RULE = {
12476
+ Inline: "inline_directive",
12477
+ Block: "block_directive"
12463
12478
  };
12479
+ var CONTAINER_KEY = Symbol();
12480
+ var LEAF_BLOCK_KEY = Symbol();
12464
12481
 
12465
- // src/plugin/helpers.ts
12466
- var CUT_REGEXP = /^{%\s*cut\s*["|'](.*)["|']\s*%}(.*)?$/;
12467
- function matchOpenToken(tokens, i) {
12468
- return tokens[i].type === "paragraph_open" && tokens[i + 1].type === "inline" && tokens[i + 1].content.match(CUT_REGEXP);
12482
+ // src/helpers/index.ts
12483
+ function enableInlineDirectives(md) {
12484
+ md.inline.ruler.enable(RULE.Inline, true);
12469
12485
  }
12470
- function matchCloseToken(tokens, i) {
12471
- return tokens[i].type === "paragraph_open" && tokens[i + 1].type === "inline" && tokens[i + 1].content.trim() === "{% endcut %}";
12486
+ function disableInlineDirectives(md) {
12487
+ md.inline.ruler.disable(RULE.Inline, true);
12472
12488
  }
12473
- function findCloseTokenIdx(tokens, idx) {
12474
- let level = 0;
12475
- let i = idx;
12476
- while (i < tokens.length) {
12477
- if (matchOpenToken(tokens, i)) {
12478
- level++;
12479
- } else if (matchCloseToken(tokens, i)) {
12480
- if (level === 0) {
12481
- return i;
12482
- }
12483
- level--;
12484
- }
12485
- i++;
12486
- }
12487
- return null;
12489
+ function enableBlockDirectives(md) {
12490
+ md.block.ruler.enable(RULE.Block, true);
12491
+ }
12492
+ function disableBlockDirectives(md) {
12493
+ md.block.ruler.disable(RULE.Block, true);
12488
12494
  }
12489
12495
 
12490
- // src/plugin/plugin.ts
12491
- var cutPlugin = (md) => {
12492
- const rule = (state) => {
12493
- const tokens = state.tokens;
12494
- let i = 0;
12495
- while (i < tokens.length) {
12496
- const match = matchOpenToken(tokens, i);
12497
- if (match) {
12498
- const closeTokenIdx = findCloseTokenIdx(tokens, i + 4);
12499
- if (!closeTokenIdx) {
12500
- i += 3;
12501
- continue;
12502
- }
12503
- const title = match[1];
12504
- const attrs = match[2] || "";
12505
- if (typeof title === "undefined") {
12506
- throw new Error(`No title provided for cut ${match[0]}`);
12507
- }
12508
- const attrsParser = new import_utils.AttrsParser(attrs);
12509
- const newOpenToken = new state.Token(TokenType.CutOpen, "details", 1);
12510
- newOpenToken.attrSet("class", ClassNames.Cut);
12511
- newOpenToken.map = tokens[i].map;
12512
- newOpenToken.markup = "{%";
12513
- attrsParser.apply(newOpenToken);
12514
- const titleOpen = new state.Token(TokenType.TitleOpen, "summary", 1);
12515
- titleOpen.attrSet("class", ClassNames.Title);
12516
- const titleInline = state.md.parseInline(title, state.env)[0];
12517
- const titleClose = new state.Token(TokenType.TitleClose, "summary", -1);
12518
- const contentOpen = new state.Token(TokenType.ContentOpen, "div", 1);
12519
- contentOpen.attrSet("class", ClassNames.Content);
12520
- if (newOpenToken.map) {
12521
- const contentOpenStart = newOpenToken.map[0] + 1;
12522
- const contentOpenEnd = newOpenToken.map[0] + 2;
12523
- contentOpen.map = [contentOpenStart, contentOpenEnd];
12524
- }
12525
- const contentClose = new state.Token(TokenType.ContentClose, "div", -1);
12526
- const newCloseToken = new state.Token(TokenType.CutClose, "details", -1);
12527
- newCloseToken.map = tokens[closeTokenIdx].map;
12528
- const insideTokens = [
12529
- newOpenToken,
12530
- titleOpen,
12531
- titleInline,
12532
- titleClose,
12533
- contentOpen,
12534
- ...tokens.slice(i + 3, closeTokenIdx),
12535
- contentClose,
12536
- newCloseToken
12537
- ];
12538
- tokens.splice(i, closeTokenIdx - i + 3, ...insideTokens);
12539
- state.env ??= {};
12540
- state.env[ENV_FLAG_NAME] = true;
12541
- i++;
12542
- } else {
12543
- i++;
12544
- }
12545
- }
12546
- };
12547
- try {
12548
- md.core.ruler.before("curly_attributes", "cut", rule);
12549
- } catch (e) {
12550
- md.core.ruler.push("cut", rule);
12551
- }
12552
- };
12496
+ // src/utils.ts
12497
+ function isFunction(arg) {
12498
+ return typeof arg === "function";
12499
+ }
12500
+ function isString(arg) {
12501
+ return typeof arg === "string";
12502
+ }
12553
12503
 
12554
- // src/plugin/utils.ts
12555
- function hidden(box, field, value) {
12556
- if (!(field in box)) {
12557
- Object.defineProperty(box, field, {
12558
- enumerable: false,
12559
- value
12560
- });
12561
- }
12562
- return box;
12504
+ // src/helpers/tokenizers.ts
12505
+ function tokenizeInlineContent(state, content) {
12506
+ const oldPos = state.pos;
12507
+ const oldPosMax = state.posMax;
12508
+ state.pos = content.startPos;
12509
+ state.posMax = content.endPos;
12510
+ state.md.inline.tokenize(state);
12511
+ state.pos = oldPos;
12512
+ state.posMax = oldPosMax;
12563
12513
  }
12564
- function copyRuntime({ runtime, output }, cache) {
12565
- const PATH_TO_RUNTIME = "../runtime";
12566
- const { join, resolve } = dynrequire("node:path");
12567
- const runtimeFiles = {
12568
- "index.js": runtime.script,
12569
- "index.css": runtime.style
12514
+ function tokenizeBlockContent(state, content, parentType) {
12515
+ const oldParent = state.parentType;
12516
+ const oldLineMax = state.lineMax;
12517
+ state.parentType = parentType ?? "directive";
12518
+ state.line = content.startLine;
12519
+ state.lineMax = content.endLine;
12520
+ state.md.block.tokenize(state, content.startLine, content.endLine);
12521
+ state.lineMax = oldLineMax;
12522
+ state.parentType = oldParent;
12523
+ }
12524
+ function createBlockInlineToken(state, { inlineContent, startLine }) {
12525
+ const token = state.push("inline", "", 0);
12526
+ token.children = [];
12527
+ token.content = inlineContent?.raw || "";
12528
+ token.map = [startLine, startLine + 1];
12529
+ return token;
12530
+ }
12531
+
12532
+ // src/helpers/registrars.ts
12533
+ function registerInlineDirective(md, name, handler) {
12534
+ md.inlineDirectives[name] = (args) => {
12535
+ const params = buildInlineParams(args);
12536
+ return handler(args.state, params);
12570
12537
  };
12571
- for (const [originFile, outputFile] of Object.entries(runtimeFiles)) {
12572
- const file = join(PATH_TO_RUNTIME, originFile);
12573
- if (!cache.has(file)) {
12574
- cache.add(file);
12575
- copy(resolve(__dirname, file), join(output, outputFile));
12576
- }
12577
- }
12578
12538
  }
12579
- function copy(from, to) {
12580
- const { mkdirSync, copyFileSync } = dynrequire("node:fs");
12581
- const { dirname } = dynrequire("node:path");
12582
- mkdirSync(dirname(to), { recursive: true });
12583
- copyFileSync(from, to);
12539
+ function registerLeafBlockDirective(md, nameOrConfig, maybeHandler) {
12540
+ const [name, handler] = isString(nameOrConfig) ? [nameOrConfig, maybeHandler] : [nameOrConfig.name, buildLeafBlockHandler(nameOrConfig)];
12541
+ md[LEAF_BLOCK_KEY] ||= {};
12542
+ md[LEAF_BLOCK_KEY][name] = handler;
12543
+ md.blockDirectives[name] = getBlockDefaultHandler(md, name);
12584
12544
  }
12585
- function dynrequire(module) {
12586
- return eval(`require('${module}')`);
12587
- }
12588
-
12589
- // src/plugin/directive.ts
12590
- var import_directive = __webpack_require__(86224);
12591
- var cutDirective = (md) => {
12592
- md.use((0, import_directive.directiveParser)());
12593
- (0, import_directive.registerContainerDirective)(md, {
12594
- name: "cut",
12595
- match(_params, state) {
12596
- state.env ??= {};
12597
- state.env[ENV_FLAG_NAME] = true;
12598
- return true;
12599
- },
12600
- container: {
12601
- tag: "details",
12602
- token: TokenType.Cut,
12603
- attrs: {
12604
- class: ClassNames.Cut
12605
- }
12606
- },
12607
- inlineContent: {
12608
- required: false,
12609
- tag: "summary",
12610
- token: TokenType.Title,
12611
- attrs: {
12612
- class: ClassNames.Title
12613
- }
12614
- },
12615
- content: {
12616
- tag: "div",
12617
- token: TokenType.Content,
12618
- attrs: {
12619
- class: ClassNames.Content
12620
- }
12621
- }
12622
- });
12623
- };
12624
-
12625
- // src/plugin/transform.ts
12626
- var registerTransform = (md, {
12627
- runtime,
12628
- bundle,
12629
- output,
12630
- directiveSyntax
12631
- }) => {
12632
- if (directiveSyntax === "disabled" || directiveSyntax === "enabled") {
12633
- md.use(cutPlugin);
12634
- }
12635
- if (directiveSyntax === "enabled" || directiveSyntax === "only") {
12636
- md.use(cutDirective);
12637
- }
12638
- md.core.ruler.push("yfm_cut_after", ({ env }) => {
12639
- hidden(env, "bundled", /* @__PURE__ */ new Set());
12640
- if (env?.[ENV_FLAG_NAME]) {
12641
- env.meta = env.meta || {};
12642
- env.meta.script = env.meta.script || [];
12643
- env.meta.script.push(runtime.script);
12644
- env.meta.style = env.meta.style || [];
12645
- env.meta.style.push(runtime.style);
12646
- if (bundle) {
12647
- copyRuntime({ runtime, output }, env.bundled);
12648
- }
12649
- }
12650
- });
12651
- };
12652
- function transform(options = {}) {
12653
- const { bundle = true } = options;
12654
- if (bundle && typeof options.runtime === "string") {
12655
- throw new TypeError("Option `runtime` should be record when `bundle` is enabled.");
12656
- }
12657
- const directiveSyntax = options.directiveSyntax || "disabled";
12658
- const runtime = typeof options.runtime === "string" ? { script: options.runtime, style: options.runtime } : options.runtime || {
12659
- script: "_assets/cut-extension.js",
12660
- style: "_assets/cut-extension.css"
12661
- };
12662
- const plugin = function(md, { output = "." } = {}) {
12663
- registerTransform(md, {
12664
- directiveSyntax,
12665
- runtime,
12666
- bundle,
12667
- output
12668
- });
12669
- };
12670
- Object.assign(plugin, {
12671
- collect(input, { destRoot = "." }) {
12672
- const MdIt = dynrequire("markdown-it");
12673
- const md = new MdIt().use((md2) => {
12674
- registerTransform(md2, {
12675
- directiveSyntax,
12676
- runtime,
12677
- bundle,
12678
- output: destRoot
12679
- });
12680
- });
12681
- md.parse(input, {});
12682
- }
12683
- });
12684
- return plugin;
12685
- }
12686
- // Annotate the CommonJS export names for ESM import in node:
12687
- 0 && 0;
12688
- //# sourceMappingURL=index.js.map
12689
-
12690
-
12691
- }),
12692
- 86224: (function (module, __unused_webpack_exports, __webpack_require__) {
12693
- "use strict";
12694
-
12695
- var __create = Object.create;
12696
- var __defProp = Object.defineProperty;
12697
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
12698
- var __getOwnPropNames = Object.getOwnPropertyNames;
12699
- var __getProtoOf = Object.getPrototypeOf;
12700
- var __hasOwnProp = Object.prototype.hasOwnProperty;
12701
- var __export = (target, all) => {
12702
- for (var name in all)
12703
- __defProp(target, name, { get: all[name], enumerable: true });
12704
- };
12705
- var __copyProps = (to, from, except, desc) => {
12706
- if (from && typeof from === "object" || typeof from === "function") {
12707
- for (let key of __getOwnPropNames(from))
12708
- if (!__hasOwnProp.call(to, key) && key !== except)
12709
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
12710
- }
12711
- return to;
12712
- };
12713
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
12714
- // If the importer is in node compatibility mode or this is not an ESM
12715
- // file that has been converted to a CommonJS file using a Babel-
12716
- // compatible transform (i.e. "__esModule" has not been set), then set
12717
- // "default" to the CommonJS "module.exports" for node compatibility.
12718
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
12719
- mod
12720
- ));
12721
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
12722
-
12723
- // src/index.ts
12724
- var src_exports = {};
12725
- __export(src_exports, {
12726
- createBlockInlineToken: () => createBlockInlineToken,
12727
- directiveParser: () => directiveParser,
12728
- disableBlockDirectives: () => disableBlockDirectives,
12729
- disableInlineDirectives: () => disableInlineDirectives,
12730
- enableBlockDirectives: () => enableBlockDirectives,
12731
- enableInlineDirectives: () => enableInlineDirectives,
12732
- registerContainerDirective: () => registerContainerDirective,
12733
- registerInlineDirective: () => registerInlineDirective,
12734
- registerLeafBlockDirective: () => registerLeafBlockDirective,
12735
- tokenizeBlockContent: () => tokenizeBlockContent,
12736
- tokenizeInlineContent: () => tokenizeInlineContent
12737
- });
12738
- module.exports = __toCommonJS(src_exports);
12739
- var import_markdown_it_directive = __toESM(__webpack_require__(20767));
12740
-
12741
- // src/const.ts
12742
- var RULE = {
12743
- Inline: "inline_directive",
12744
- Block: "block_directive"
12745
- };
12746
- var CONTAINER_KEY = Symbol();
12747
- var LEAF_BLOCK_KEY = Symbol();
12748
-
12749
- // src/helpers/index.ts
12750
- function enableInlineDirectives(md) {
12751
- md.inline.ruler.enable(RULE.Inline, true);
12752
- }
12753
- function disableInlineDirectives(md) {
12754
- md.inline.ruler.disable(RULE.Inline, true);
12755
- }
12756
- function enableBlockDirectives(md) {
12757
- md.block.ruler.enable(RULE.Block, true);
12758
- }
12759
- function disableBlockDirectives(md) {
12760
- md.block.ruler.disable(RULE.Block, true);
12761
- }
12762
-
12763
- // src/utils.ts
12764
- function isFunction(arg) {
12765
- return typeof arg === "function";
12766
- }
12767
- function isString(arg) {
12768
- return typeof arg === "string";
12769
- }
12770
-
12771
- // src/helpers/tokenizers.ts
12772
- function tokenizeInlineContent(state, content) {
12773
- const oldPos = state.pos;
12774
- const oldPosMax = state.posMax;
12775
- state.pos = content.startPos;
12776
- state.posMax = content.endPos;
12777
- state.md.inline.tokenize(state);
12778
- state.pos = oldPos;
12779
- state.posMax = oldPosMax;
12780
- }
12781
- function tokenizeBlockContent(state, content, parentType) {
12782
- const oldParent = state.parentType;
12783
- const oldLineMax = state.lineMax;
12784
- state.parentType = parentType ?? "directive";
12785
- state.line = content.startLine;
12786
- state.lineMax = content.endLine;
12787
- state.md.block.tokenize(state, content.startLine, content.endLine);
12788
- state.lineMax = oldLineMax;
12789
- state.parentType = oldParent;
12790
- }
12791
- function createBlockInlineToken(state, { inlineContent, startLine }) {
12792
- const token = state.push("inline", "", 0);
12793
- token.children = [];
12794
- token.content = inlineContent?.raw || "";
12795
- token.map = [startLine, startLine + 1];
12796
- return token;
12797
- }
12798
-
12799
- // src/helpers/registrars.ts
12800
- function registerInlineDirective(md, name, handler) {
12801
- md.inlineDirectives[name] = (args) => {
12802
- const params = buildInlineParams(args);
12803
- return handler(args.state, params);
12804
- };
12805
- }
12806
- function registerLeafBlockDirective(md, nameOrConfig, maybeHandler) {
12807
- const [name, handler] = isString(nameOrConfig) ? [nameOrConfig, maybeHandler] : [nameOrConfig.name, buildLeafBlockHandler(nameOrConfig)];
12808
- md[LEAF_BLOCK_KEY] ||= {};
12809
- md[LEAF_BLOCK_KEY][name] = handler;
12810
- md.blockDirectives[name] = getBlockDefaultHandler(md, name);
12811
- }
12812
- function registerContainerDirective(md, nameOrConfig, maybeHandler) {
12813
- const [name, handler] = isString(nameOrConfig) ? [nameOrConfig, maybeHandler] : [
12814
- nameOrConfig.name,
12815
- nameOrConfig.type === "code_block" ? buildCodeContainerHandler(nameOrConfig) : buildContainerHandler(nameOrConfig)
12816
- ];
12817
- md[CONTAINER_KEY] ||= {};
12818
- md[CONTAINER_KEY][name] = handler;
12819
- md.blockDirectives[name] = getBlockDefaultHandler(md, name);
12545
+ function registerContainerDirective(md, nameOrConfig, maybeHandler) {
12546
+ const [name, handler] = isString(nameOrConfig) ? [nameOrConfig, maybeHandler] : [
12547
+ nameOrConfig.name,
12548
+ nameOrConfig.type === "code_block" ? buildCodeContainerHandler(nameOrConfig) : buildContainerHandler(nameOrConfig)
12549
+ ];
12550
+ md[CONTAINER_KEY] ||= {};
12551
+ md[CONTAINER_KEY][name] = handler;
12552
+ md.blockDirectives[name] = getBlockDefaultHandler(md, name);
12820
12553
  }
12821
12554
  function getBlockDefaultHandler(md, name) {
12822
12555
  return (args) => {
@@ -18339,7 +18072,7 @@ module.exports = code;
18339
18072
  58285: (function (module, __unused_webpack_exports, __webpack_require__) {
18340
18073
  "use strict";
18341
18074
 
18342
- const cut_extension_1 = __webpack_require__(14060);
18075
+ const cut_extension_1 = __webpack_require__(4103);
18343
18076
  module.exports = (0, cut_extension_1.transform)({ bundle: false, directiveSyntax: 'disabled' });
18344
18077
  //# sourceMappingURL=cut.js.map
18345
18078
 
@@ -21292,6 +21025,284 @@ function getRealPath(symlinkPath) {
21292
21025
  exports.getRealPath = getRealPath;
21293
21026
  //# sourceMappingURL=utilsFS.js.map
21294
21027
 
21028
+ }),
21029
+ 4103: (function (module, __unused_webpack_exports, __webpack_require__) {
21030
+ "use strict";
21031
+
21032
+ var __defProp = Object.defineProperty;
21033
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
21034
+ var __getOwnPropNames = Object.getOwnPropertyNames;
21035
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
21036
+ var __export = (target, all) => {
21037
+ for (var name in all)
21038
+ __defProp(target, name, { get: all[name], enumerable: true });
21039
+ };
21040
+ var __copyProps = (to, from, except, desc) => {
21041
+ if (from && typeof from === "object" || typeof from === "function") {
21042
+ for (let key of __getOwnPropNames(from))
21043
+ if (!__hasOwnProp.call(to, key) && key !== except)
21044
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
21045
+ }
21046
+ return to;
21047
+ };
21048
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
21049
+
21050
+ // src/plugin/index.ts
21051
+ var plugin_exports = {};
21052
+ __export(plugin_exports, {
21053
+ TokenType: () => TokenType,
21054
+ transform: () => transform
21055
+ });
21056
+ module.exports = __toCommonJS(plugin_exports);
21057
+
21058
+ // src/plugin/plugin.ts
21059
+ var import_utils = __webpack_require__(87910);
21060
+
21061
+ // src/plugin/const.ts
21062
+ var ENV_FLAG_NAME = "has-yfm-cut";
21063
+ var TokenType = {
21064
+ Cut: "yfm_cut",
21065
+ CutOpen: "yfm_cut_open",
21066
+ CutClose: "yfm_cut_close",
21067
+ Title: "yfm_cut_title",
21068
+ TitleOpen: "yfm_cut_title_open",
21069
+ TitleClose: "yfm_cut_title_close",
21070
+ Content: "yfm_cut_content",
21071
+ ContentOpen: "yfm_cut_content_open",
21072
+ ContentClose: "yfm_cut_content_close"
21073
+ };
21074
+ var ClassNames = {
21075
+ Cut: "yfm-cut",
21076
+ Title: "yfm-cut-title",
21077
+ Content: "yfm-cut-content"
21078
+ };
21079
+
21080
+ // src/plugin/helpers.ts
21081
+ var CUT_REGEXP = /^{%\s*cut\s*["|'](.*)["|']\s*%}(.*)?$/;
21082
+ function matchOpenToken(tokens, i) {
21083
+ return tokens[i].type === "paragraph_open" && tokens[i + 1].type === "inline" && tokens[i + 1].content.match(CUT_REGEXP);
21084
+ }
21085
+ function matchCloseToken(tokens, i) {
21086
+ return tokens[i].type === "paragraph_open" && tokens[i + 1].type === "inline" && tokens[i + 1].content.trim() === "{% endcut %}";
21087
+ }
21088
+ function findCloseTokenIdx(tokens, idx) {
21089
+ let level = 0;
21090
+ let i = idx;
21091
+ while (i < tokens.length) {
21092
+ if (matchOpenToken(tokens, i)) {
21093
+ level++;
21094
+ } else if (matchCloseToken(tokens, i)) {
21095
+ if (level === 0) {
21096
+ return i;
21097
+ }
21098
+ level--;
21099
+ }
21100
+ i++;
21101
+ }
21102
+ return null;
21103
+ }
21104
+
21105
+ // src/plugin/plugin.ts
21106
+ var cutPlugin = (md) => {
21107
+ const rule = (state) => {
21108
+ const tokens = state.tokens;
21109
+ let i = 0;
21110
+ while (i < tokens.length) {
21111
+ const match = matchOpenToken(tokens, i);
21112
+ if (match) {
21113
+ const closeTokenIdx = findCloseTokenIdx(tokens, i + 4);
21114
+ if (!closeTokenIdx) {
21115
+ i += 3;
21116
+ continue;
21117
+ }
21118
+ const title = match[1];
21119
+ const attrs = match[2] || "";
21120
+ if (typeof title === "undefined") {
21121
+ throw new Error(`No title provided for cut ${match[0]}`);
21122
+ }
21123
+ const attrsParser = new import_utils.AttrsParser(attrs);
21124
+ const newOpenToken = new state.Token(TokenType.CutOpen, "details", 1);
21125
+ newOpenToken.attrSet("class", ClassNames.Cut);
21126
+ newOpenToken.map = tokens[i].map;
21127
+ newOpenToken.markup = "{%";
21128
+ attrsParser.apply(newOpenToken);
21129
+ const titleOpen = new state.Token(TokenType.TitleOpen, "summary", 1);
21130
+ titleOpen.attrSet("class", ClassNames.Title);
21131
+ const titleInline = state.md.parseInline(title, state.env)[0];
21132
+ const titleClose = new state.Token(TokenType.TitleClose, "summary", -1);
21133
+ const contentOpen = new state.Token(TokenType.ContentOpen, "div", 1);
21134
+ contentOpen.attrSet("class", ClassNames.Content);
21135
+ if (newOpenToken.map) {
21136
+ const contentOpenStart = newOpenToken.map[0] + 1;
21137
+ const contentOpenEnd = newOpenToken.map[0] + 2;
21138
+ contentOpen.map = [contentOpenStart, contentOpenEnd];
21139
+ }
21140
+ const contentClose = new state.Token(TokenType.ContentClose, "div", -1);
21141
+ const newCloseToken = new state.Token(TokenType.CutClose, "details", -1);
21142
+ newCloseToken.map = tokens[closeTokenIdx].map;
21143
+ const insideTokens = [
21144
+ newOpenToken,
21145
+ titleOpen,
21146
+ titleInline,
21147
+ titleClose,
21148
+ contentOpen,
21149
+ ...tokens.slice(i + 3, closeTokenIdx),
21150
+ contentClose,
21151
+ newCloseToken
21152
+ ];
21153
+ tokens.splice(i, closeTokenIdx - i + 3, ...insideTokens);
21154
+ state.env ??= {};
21155
+ state.env[ENV_FLAG_NAME] = true;
21156
+ i++;
21157
+ } else {
21158
+ i++;
21159
+ }
21160
+ }
21161
+ };
21162
+ try {
21163
+ md.core.ruler.before("curly_attributes", "cut", rule);
21164
+ } catch (e) {
21165
+ md.core.ruler.push("cut", rule);
21166
+ }
21167
+ };
21168
+
21169
+ // src/plugin/utils.ts
21170
+ function hidden(box, field, value) {
21171
+ if (!(field in box)) {
21172
+ Object.defineProperty(box, field, {
21173
+ enumerable: false,
21174
+ value
21175
+ });
21176
+ }
21177
+ return box;
21178
+ }
21179
+ function copyRuntime({ runtime, output }, cache) {
21180
+ const PATH_TO_RUNTIME = "../runtime";
21181
+ const { join, resolve } = dynrequire("node:path");
21182
+ const runtimeFiles = {
21183
+ "index.js": runtime.script,
21184
+ "index.css": runtime.style
21185
+ };
21186
+ for (const [originFile, outputFile] of Object.entries(runtimeFiles)) {
21187
+ const file = join(PATH_TO_RUNTIME, originFile);
21188
+ if (!cache.has(file)) {
21189
+ cache.add(file);
21190
+ copy(resolve(__dirname, file), join(output, outputFile));
21191
+ }
21192
+ }
21193
+ }
21194
+ function copy(from, to) {
21195
+ const { mkdirSync, copyFileSync } = dynrequire("node:fs");
21196
+ const { dirname } = dynrequire("node:path");
21197
+ mkdirSync(dirname(to), { recursive: true });
21198
+ copyFileSync(from, to);
21199
+ }
21200
+ function dynrequire(module) {
21201
+ return eval(`require('${module}')`);
21202
+ }
21203
+
21204
+ // src/plugin/directive.ts
21205
+ var import_directive = __webpack_require__(86224);
21206
+ var cutDirective = (md) => {
21207
+ md.use((0, import_directive.directiveParser)());
21208
+ (0, import_directive.registerContainerDirective)(md, {
21209
+ name: "cut",
21210
+ match(_params, state) {
21211
+ state.env ??= {};
21212
+ state.env[ENV_FLAG_NAME] = true;
21213
+ return true;
21214
+ },
21215
+ container: {
21216
+ tag: "details",
21217
+ token: TokenType.Cut,
21218
+ attrs: {
21219
+ class: ClassNames.Cut
21220
+ }
21221
+ },
21222
+ inlineContent: {
21223
+ required: false,
21224
+ tag: "summary",
21225
+ token: TokenType.Title,
21226
+ attrs: {
21227
+ class: ClassNames.Title
21228
+ }
21229
+ },
21230
+ content: {
21231
+ tag: "div",
21232
+ token: TokenType.Content,
21233
+ attrs: {
21234
+ class: ClassNames.Content
21235
+ }
21236
+ }
21237
+ });
21238
+ };
21239
+
21240
+ // src/plugin/transform.ts
21241
+ var registerTransform = (md, {
21242
+ runtime,
21243
+ bundle,
21244
+ output,
21245
+ directiveSyntax
21246
+ }) => {
21247
+ if (directiveSyntax === "disabled" || directiveSyntax === "enabled") {
21248
+ md.use(cutPlugin);
21249
+ }
21250
+ if (directiveSyntax === "enabled" || directiveSyntax === "only") {
21251
+ md.use(cutDirective);
21252
+ }
21253
+ md.core.ruler.push("yfm_cut_after", ({ env }) => {
21254
+ hidden(env, "bundled", /* @__PURE__ */ new Set());
21255
+ if (env?.[ENV_FLAG_NAME]) {
21256
+ env.meta = env.meta || {};
21257
+ env.meta.script = env.meta.script || [];
21258
+ env.meta.script.push(runtime.script);
21259
+ env.meta.style = env.meta.style || [];
21260
+ env.meta.style.push(runtime.style);
21261
+ if (bundle) {
21262
+ copyRuntime({ runtime, output }, env.bundled);
21263
+ }
21264
+ }
21265
+ });
21266
+ };
21267
+ function transform(options = {}) {
21268
+ const { bundle = true } = options;
21269
+ if (bundle && typeof options.runtime === "string") {
21270
+ throw new TypeError("Option `runtime` should be record when `bundle` is enabled.");
21271
+ }
21272
+ const directiveSyntax = options.directiveSyntax || "disabled";
21273
+ const runtime = typeof options.runtime === "string" ? { script: options.runtime, style: options.runtime } : options.runtime || {
21274
+ script: "_assets/cut-extension.js",
21275
+ style: "_assets/cut-extension.css"
21276
+ };
21277
+ const plugin = function(md, { output = "." } = {}) {
21278
+ registerTransform(md, {
21279
+ directiveSyntax,
21280
+ runtime,
21281
+ bundle,
21282
+ output
21283
+ });
21284
+ };
21285
+ Object.assign(plugin, {
21286
+ collect(input, { destRoot = "." }) {
21287
+ const MdIt = dynrequire("markdown-it");
21288
+ const md = new MdIt().use((md2) => {
21289
+ registerTransform(md2, {
21290
+ directiveSyntax,
21291
+ runtime,
21292
+ bundle,
21293
+ output: destRoot
21294
+ });
21295
+ });
21296
+ md.parse(input, {});
21297
+ }
21298
+ });
21299
+ return plugin;
21300
+ }
21301
+ // Annotate the CommonJS export names for ESM import in node:
21302
+ 0 && 0;
21303
+ //# sourceMappingURL=index.js.map
21304
+
21305
+
21295
21306
  }),
21296
21307
  87910: (function (module) {
21297
21308
  "use strict";