@diplodoc/tabs-extension 3.10.7 → 3.10.8-transform5.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.
@@ -1,2 +1,4 @@
1
1
  /** Tabs extension: MarkdownIt plugin that transforms `{% list tabs %}` into tab HTML. */
2
2
  export { transform } from './transform';
3
+ export type { PluginOptions, TabsPlugin, TransformOptions } from './transform';
4
+ export type { MarkdownIt, StateCore, Token } from './markdown-it';
@@ -1136,7 +1136,6 @@ function generateTabsTokens(tabs, state, props2) {
1136
1136
  }
1137
1137
 
1138
1138
  // src/plugin/find.ts
1139
- var import_token = __toESM(require("markdown-it/lib/token"));
1140
1139
  function findCloseTokenIndex(tokens, idx) {
1141
1140
  let level = 0;
1142
1141
  let i = idx;
@@ -1235,14 +1234,14 @@ function tryToFindTabs(tokens, index) {
1235
1234
  extraTokensAfterClose
1236
1235
  };
1237
1236
  }
1238
- function findTabs(tokens, idx, closeTokenIdx) {
1237
+ function findTabs(tokens, idx, closeTokenIdx, TokenConstructor) {
1239
1238
  const tabs = [];
1240
1239
  let i = idx;
1241
1240
  let nestedLevel = -1;
1242
1241
  let pending = {
1243
1242
  name: "",
1244
1243
  tokens: [],
1245
- listItem: new import_token.default("list_item_open", "", 0)
1244
+ listItem: new TokenConstructor("list_item_open", "", 0)
1246
1245
  };
1247
1246
  while (i < tokens.length) {
1248
1247
  const token = tokens[i];
@@ -1305,21 +1304,35 @@ var defaultFeatures = {
1305
1304
  }
1306
1305
  };
1307
1306
  var runsCounter = 0;
1308
- function transform({
1309
- runtimeJsPath = "_assets/tabs-extension.js",
1310
- runtimeCssPath = "_assets/tabs-extension.css",
1311
- containerClasses = "",
1312
- bundle = true,
1313
- features = defaultFeatures,
1314
- onBundle
1315
- } = {}) {
1316
- return function tabs(md, options) {
1317
- const { output = ".", generateID: externalGenerateID } = options || {};
1307
+ function appendRuntimeMeta(env, runtimeJsPath, runtimeCssPath) {
1308
+ const meta = env.meta || (env.meta = {});
1309
+ if (typeof meta !== "object" || meta === null) {
1310
+ throw new TypeError("Expected env.meta to be an object.");
1311
+ }
1312
+ if (!("script" in meta) || !meta.script) Object.assign(meta, { script: [] });
1313
+ if (!("style" in meta) || !meta.style) Object.assign(meta, { style: [] });
1314
+ if (!("script" in meta) || !Array.isArray(meta.script) || !("style" in meta) || !Array.isArray(meta.style)) {
1315
+ throw new TypeError("Expected runtime script and style arrays.");
1316
+ }
1317
+ meta.script.push(runtimeJsPath);
1318
+ meta.style.push(runtimeCssPath);
1319
+ }
1320
+ function transform(options = {}) {
1321
+ const {
1322
+ runtimeJsPath = "_assets/tabs-extension.js",
1323
+ runtimeCssPath = "_assets/tabs-extension.css",
1324
+ containerClasses = "",
1325
+ bundle = true,
1326
+ features = defaultFeatures,
1327
+ onBundle
1328
+ } = options;
1329
+ return function tabs(md, options2) {
1330
+ const { output = ".", generateID: externalGenerateID } = options2 || {};
1318
1331
  const generateID = externalGenerateID != null ? externalGenerateID : (0, import_utils6.createIDGeneratorByStrategy)("random");
1319
1332
  const plugin = (state) => {
1320
- const { env, tokens } = state;
1333
+ const { tokens } = state;
1334
+ const env = addHiddenProperty(state.env, "bundled", /* @__PURE__ */ new Set());
1321
1335
  const runId = String(++runsCounter);
1322
- addHiddenProperty(env, "bundled", /* @__PURE__ */ new Set());
1323
1336
  let i = 0;
1324
1337
  let tabsAreInserted = false;
1325
1338
  while (i < tokens.length) {
@@ -1333,7 +1346,7 @@ function transform({
1333
1346
  if (!features.enabledVariants[parsedProps.variant]) {
1334
1347
  parsedProps.variant = "regular" /* Regular */;
1335
1348
  }
1336
- const tabs2 = findTabs(state.tokens, i + 3, closeTokenIndex);
1349
+ const tabs2 = findTabs(state.tokens, i + 3, closeTokenIndex, state.Token);
1337
1350
  if (tabs2.length > 0) {
1338
1351
  const tabsTokens = generateTabsTokens(tabs2, state, {
1339
1352
  containerClasses,
@@ -1354,11 +1367,7 @@ function transform({
1354
1367
  }
1355
1368
  }
1356
1369
  if (tabsAreInserted) {
1357
- env.meta = env.meta || {};
1358
- env.meta.script = env.meta.script || [];
1359
- env.meta.style = env.meta.style || [];
1360
- env.meta.script.push(runtimeJsPath);
1361
- env.meta.style.push(runtimeCssPath);
1370
+ appendRuntimeMeta(env, runtimeJsPath, runtimeCssPath);
1362
1371
  if (bundle && onBundle) {
1363
1372
  onBundle({ runtimeJsPath, runtimeCssPath, output }, env.bundled);
1364
1373
  }