polytypo 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +31 -0
  3. package/dist/chunk-47XAYIKV.js +5635 -0
  4. package/dist/chunk-47XAYIKV.js.map +1 -0
  5. package/dist/chunk-7IZAODBB.cjs +17 -0
  6. package/dist/chunk-7IZAODBB.cjs.map +1 -0
  7. package/dist/chunk-7L4ECXDJ.js +19 -0
  8. package/dist/chunk-7L4ECXDJ.js.map +1 -0
  9. package/dist/chunk-DZ72ITYV.cjs +19 -0
  10. package/dist/chunk-DZ72ITYV.cjs.map +1 -0
  11. package/dist/chunk-E63PQ3N7.js +297 -0
  12. package/dist/chunk-E63PQ3N7.js.map +1 -0
  13. package/dist/chunk-F3BDCZSG.cjs +21 -0
  14. package/dist/chunk-F3BDCZSG.cjs.map +1 -0
  15. package/dist/chunk-HZPDGNOO.js +163 -0
  16. package/dist/chunk-HZPDGNOO.js.map +1 -0
  17. package/dist/chunk-M2UGLSIB.cjs +163 -0
  18. package/dist/chunk-M2UGLSIB.cjs.map +1 -0
  19. package/dist/chunk-MMU4UU46.js +17 -0
  20. package/dist/chunk-MMU4UU46.js.map +1 -0
  21. package/dist/chunk-MOVY7OL2.cjs +5635 -0
  22. package/dist/chunk-MOVY7OL2.cjs.map +1 -0
  23. package/dist/chunk-UKWVAQMR.js +21 -0
  24. package/dist/chunk-UKWVAQMR.js.map +1 -0
  25. package/dist/chunk-YS3FXB5V.cjs +297 -0
  26. package/dist/chunk-YS3FXB5V.cjs.map +1 -0
  27. package/dist/errors-joZChNws.d.cts +120 -0
  28. package/dist/errors-joZChNws.d.ts +120 -0
  29. package/dist/html.cjs +22 -0
  30. package/dist/html.cjs.map +1 -0
  31. package/dist/html.d.cts +16 -0
  32. package/dist/html.d.ts +16 -0
  33. package/dist/html.js +22 -0
  34. package/dist/html.js.map +1 -0
  35. package/dist/index.cjs +40 -0
  36. package/dist/index.cjs.map +1 -0
  37. package/dist/index.d.cts +6 -0
  38. package/dist/index.d.ts +6 -0
  39. package/dist/index.js +40 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/markdown.cjs +22 -0
  42. package/dist/markdown.cjs.map +1 -0
  43. package/dist/markdown.d.cts +19 -0
  44. package/dist/markdown.d.ts +19 -0
  45. package/dist/markdown.js +22 -0
  46. package/dist/markdown.js.map +1 -0
  47. package/dist/text.cjs +21 -0
  48. package/dist/text.cjs.map +1 -0
  49. package/dist/text.d.cts +17 -0
  50. package/dist/text.d.ts +17 -0
  51. package/dist/text.js +21 -0
  52. package/dist/text.js.map +1 -0
  53. package/package.json +134 -0
@@ -0,0 +1,163 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+
6
+ var _chunkYS3FXB5Vcjs = require('./chunk-YS3FXB5V.cjs');
7
+
8
+
9
+
10
+
11
+ var _chunkMOVY7OL2cjs = require('./chunk-MOVY7OL2.cjs');
12
+
13
+ // src/modes/markdown.ts
14
+ var _micromark = require('micromark');
15
+ var _micromarkextensionfrontmatter = require('micromark-extension-frontmatter');
16
+ var _micromarkextensiongfm = require('micromark-extension-gfm');
17
+ var _micromarkextensionmdxjs = require('micromark-extension-mdxjs');
18
+ var SKIPPED_TOKEN_TYPES = /* @__PURE__ */ new Set([
19
+ // fenced code blocks (including the info string and the fences) and indented code blocks
20
+ "codeFenced",
21
+ "codeIndented",
22
+ // inline code spans, including the backticks
23
+ "codeText",
24
+ // autolinks `<https://…>`, and GFM's bare-URL form
25
+ "autolink",
26
+ "literalAutolink",
27
+ // link and image destinations and titles; the definition line of a reference link. The link
28
+ // *text* is a `labelText`, which is not skipped.
29
+ "resource",
30
+ "reference",
31
+ "definition",
32
+ // MDX: expression containers in full, and every JSX attribute — the whole tag is skipped, so
33
+ // attributes never surface. JSX element *children* sit outside the tag tokens and are
34
+ // processable.
35
+ "mdxFlowExpression",
36
+ "mdxTextExpression",
37
+ "mdxjsEsm",
38
+ // Not in modes.md 3.7, and it has to be: without it the second `---` of a YAML block reads as
39
+ // a setext underline, `title: Une note` becomes a paragraph, and `fr` puts a narrow no-break
40
+ // space in front of the colon of a machine-read metadata field. Reported as a spec gap.
41
+ "frontmatter"
42
+ ]);
43
+ var RAW_TAG_TOKEN_TYPES = /* @__PURE__ */ new Set([
44
+ "htmlText",
45
+ "mdxJsxTextTag",
46
+ "mdxJsxFlowTag"
47
+ ]);
48
+ var LESS_THAN = 60;
49
+ var GREATER_THAN = 62;
50
+ var SLASH = 47;
51
+ var EXCLAMATION = 33;
52
+ var QUESTION = 63;
53
+ function isAsciiLetter(unit) {
54
+ return unit >= 97 && unit <= 122 || unit >= 65 && unit <= 90;
55
+ }
56
+ function isTagNameUnit(unit) {
57
+ return unit !== GREATER_THAN && unit !== SLASH && unit !== 32 && unit !== 9 && unit !== 10 && unit !== 13;
58
+ }
59
+ function asciiLower(value) {
60
+ let out = "";
61
+ for (let i = 0; i < value.length; i += 1) {
62
+ const unit = value.charCodeAt(i);
63
+ out += unit >= 65 && unit <= 90 ? String.fromCharCode(unit + 32) : value[i];
64
+ }
65
+ return out;
66
+ }
67
+ function readTag(tag) {
68
+ if (tag.charCodeAt(0) !== LESS_THAN) return null;
69
+ let i = 1;
70
+ const closing = tag.charCodeAt(i) === SLASH;
71
+ if (closing) i += 1;
72
+ if (tag.charCodeAt(i) === EXCLAMATION || tag.charCodeAt(i) === QUESTION) return null;
73
+ if (!isAsciiLetter(tag.charCodeAt(i))) return null;
74
+ const nameAt = i;
75
+ while (i < tag.length && isTagNameUnit(tag.charCodeAt(i))) i += 1;
76
+ const selfClosing = tag.charCodeAt(tag.length - 2) === SLASH;
77
+ return { name: tag.slice(nameAt, i), closing, selfClosing };
78
+ }
79
+ function updateElementStack(stack, tag, caseSensitive) {
80
+ const parsed = readTag(tag);
81
+ if (parsed === null) return;
82
+ const name = caseSensitive ? parsed.name : asciiLower(parsed.name);
83
+ if (parsed.closing) {
84
+ if (stack[stack.length - 1] === name) stack.pop();
85
+ return;
86
+ }
87
+ if (!parsed.selfClosing && _chunkYS3FXB5Vcjs.isSkippedElement.call(void 0, name)) stack.push(name);
88
+ }
89
+ function tokenize(source, extensions) {
90
+ return _micromark.postprocess.call(void 0,
91
+ _micromark.parse.call(void 0, { extensions: [...extensions] }).document().write(_micromark.preprocess.call(void 0, )(source, null, true))
92
+ );
93
+ }
94
+ function resolveDialect(dialect) {
95
+ if (dialect === "commonmark" || dialect === "mdx") return dialect;
96
+ if (dialect === void 0) {
97
+ throw new (0, _chunkMOVY7OL2cjs.PolytypoError)(
98
+ "POLYTYPO_INVALID_DIALECT",
99
+ 'Mode "markdown" requires a dialect. Expected "commonmark" or "mdx"; there is no default.'
100
+ );
101
+ }
102
+ throw new (0, _chunkMOVY7OL2cjs.PolytypoError)(
103
+ "POLYTYPO_INVALID_DIALECT",
104
+ `Unknown dialect "${String(dialect)}". Expected "commonmark" or "mdx".`
105
+ );
106
+ }
107
+ function extensionsFor(dialect) {
108
+ return dialect === "mdx" ? [_micromarkextensionfrontmatter.frontmatter.call(void 0, ), _micromarkextensiongfm.gfm.call(void 0, ), _micromarkextensionmdxjs.mdxjs.call(void 0, )] : [_micromarkextensionfrontmatter.frontmatter.call(void 0, ), _micromarkextensiongfm.gfm.call(void 0, )];
109
+ }
110
+ function markdownSpans(source, dialect) {
111
+ const events = _chunkYS3FXB5Vcjs.wrapParserErrors.call(void 0, dialect, () => tokenize(source, extensionsFor(dialect)));
112
+ const spans = [];
113
+ const elementStack = [];
114
+ let skipDepth = 0;
115
+ for (const [kind, token] of events) {
116
+ const type = token.type;
117
+ if (SKIPPED_TOKEN_TYPES.has(type)) {
118
+ skipDepth += kind === "enter" ? 1 : -1;
119
+ continue;
120
+ }
121
+ if (RAW_TAG_TOKEN_TYPES.has(type)) {
122
+ if (kind === "enter") {
123
+ updateElementStack(
124
+ elementStack,
125
+ source.slice(token.start.offset, token.end.offset),
126
+ type !== "htmlText"
127
+ );
128
+ }
129
+ skipDepth += kind === "enter" ? 1 : -1;
130
+ continue;
131
+ }
132
+ if (type === "htmlFlow") {
133
+ if (kind === "enter" && skipDepth === 0 && elementStack.length === 0) {
134
+ for (const span of _chunkYS3FXB5Vcjs.htmlFragmentSpans.call(void 0,
135
+ source.slice(token.start.offset, token.end.offset),
136
+ token.start.offset
137
+ )) {
138
+ spans.push(span);
139
+ }
140
+ }
141
+ skipDepth += kind === "enter" ? 1 : -1;
142
+ continue;
143
+ }
144
+ if (kind === "enter" && type === "data" && skipDepth === 0 && elementStack.length === 0) {
145
+ spans.push({ start: token.start.offset, end: token.end.offset });
146
+ }
147
+ }
148
+ return spans;
149
+ }
150
+
151
+ // src/engine/markdown-pipeline.ts
152
+ function runMarkdownPipeline(input, options) {
153
+ const planned = _chunkMOVY7OL2cjs.planRules.call(void 0, options.rules);
154
+ const locale = _chunkMOVY7OL2cjs.getLocaleData.call(void 0, options.locale);
155
+ const dialect = resolveDialect(options.dialect);
156
+ const spans = markdownSpans(input, dialect);
157
+ return _chunkYS3FXB5Vcjs.runOverSpans.call(void 0, input, spans, planned, locale, "markdown");
158
+ }
159
+
160
+
161
+
162
+ exports.runMarkdownPipeline = runMarkdownPipeline;
163
+ //# sourceMappingURL=chunk-M2UGLSIB.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/polytypo-js/polytypo-js/dist/chunk-M2UGLSIB.cjs","../src/modes/markdown.ts","../src/engine/markdown-pipeline.ts"],"names":[],"mappings":"AAAA;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;ACZA,sCAA+C;AAC/C,gFAA4B;AAC5B,gEAAoB;AACpB,oEAAsB;AAgBtB,IAAM,oBAAA,kBAA2C,IAAI,GAAA,CAAI;AAAA;AAAA,EAEvD,YAAA;AAAA,EACA,cAAA;AAAA;AAAA,EAEA,UAAA;AAAA;AAAA,EAEA,UAAA;AAAA,EACA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AAM,KAAA,CAAM,KAAA,CAAM,MAAA,EAAQ,KAAA,CAAM,GAAA,CAAI,MAAM,CAAA;AAAA,UACjD,KAAA,CAAM,KAAA,CAAM;AAAA,QACd,CAAA,EAAG;AACD,UAAA,KAAA,CAAM,IAAA,CAAK,IAAI,CAAA;AAAA,QACjB;AAAA,MACF;AACA,MAAA,UAAA,GAAa,KAAA,IAAS,QAAA,EAAU,EAAA,EAAI,CAAA,CAAA;AACpC,MAAA,QAAA;AAAA,IACF;AAEA,IAAA,GAAA,CAAI,KAAA,IAAS,QAAA,GAAW,KAAA,IAAS,OAAA,GAAU,UAAA,IAAc,EAAA,GAAK,YAAA,CAAa,OAAA,IAAW,CAAA,EAAG;AACvF,MAAA,KAAA,CAAM,IAAA,CAAK,EAAE,KAAA,EAAO,KAAA,CAAM,KAAA,CAAM,MAAA,EAAQ,GAAA,EAAK,KAAA,CAAM,GAAA,CAAI,OAAO,CAAC,CAAA;AAAA,IACjE;AAAA,EACF;AAEA,EAAA,OAAO,KAAA;AACT;ADrDA;AACA;AEtIO,SAAS,mBAAA,CAAoB,KAAA,EAAe,OAAA,EAAmC;AACpF,EAAA,MAAM,QAAA,EAAU,yCAAA,OAAU,CAAQ,KAAK,CAAA;AACvC,EAAA,MAAM,OAAA,EAAS,6CAAA,OAAc,CAAQ,MAAM,CAAA;AAC3C,EAAA,MAAM,QAAA,EAAU,cAAA,CAAe,OAAA,CAAQ,OAAO,CAAA;AAC9C,EAAA,MAAM,MAAA,EAAQ,aAAA,CAAc,KAAA,EAAO,OAAO,CAAA;AAC1C,EAAA,OAAO,4CAAA,KAAa,EAAO,KAAA,EAAO,OAAA,EAAS,MAAA,EAAQ,UAAU,CAAA;AAC/D;AFwIA;AACA;AACE;AACF,kDAAC","file":"/home/runner/work/polytypo-js/polytypo-js/dist/chunk-M2UGLSIB.cjs","sourcesContent":[null,"import { parse, postprocess, preprocess } from \"micromark\";\nimport { frontmatter } from \"micromark-extension-frontmatter\";\nimport { gfm } from \"micromark-extension-gfm\";\nimport { mdxjs } from \"micromark-extension-mdxjs\";\nimport type { Event, Extension } from \"micromark-util-types\";\nimport { PolytypoError } from \"../errors.js\";\nimport type { Dialect } from \"../types.js\";\nimport { htmlFragmentSpans, isSkippedElement } from \"./html.js\";\nimport { wrapParserErrors } from \"./parse-error.js\";\nimport type { Span } from \"./spans.js\";\n\n/**\n * spec/rules/modes.md 3.7. Each entry is skipped **whole**, including anything that looks\n * processable inside it. The complement is not enumerated: a span is emitted only for a\n * micromark `data` token, which is the tokenizer's own name for \"literal content\", so list\n * markers, emphasis delimiters, heading sequences, table padding, line endings, hard-break\n * spaces, character escapes and character references are outside every span by construction\n * rather than by a second list that could drift from the first.\n */\nconst SKIPPED_TOKEN_TYPES: ReadonlySet<string> = new Set([\n // fenced code blocks (including the info string and the fences) and indented code blocks\n \"codeFenced\",\n \"codeIndented\",\n // inline code spans, including the backticks\n \"codeText\",\n // autolinks `<https://…>`, and GFM's bare-URL form\n \"autolink\",\n \"literalAutolink\",\n // link and image destinations and titles; the definition line of a reference link. The link\n // *text* is a `labelText`, which is not skipped.\n \"resource\",\n \"reference\",\n \"definition\",\n // MDX: expression containers in full, and every JSX attribute — the whole tag is skipped, so\n // attributes never surface. JSX element *children* sit outside the tag tokens and are\n // processable.\n \"mdxFlowExpression\",\n \"mdxTextExpression\",\n \"mdxjsEsm\",\n // Not in modes.md 3.7, and it has to be: without it the second `---` of a YAML block reads as\n // a setext underline, `title: Une note` becomes a paragraph, and `fr` puts a narrow no-break\n // space in front of the colon of a machine-read metadata field. Reported as a spec gap.\n \"frontmatter\",\n]);\n\n/** Token types whose enter/exit also maintains the skipped-element stack. */\nconst RAW_TAG_TOKEN_TYPES: ReadonlySet<string> = new Set([\n \"htmlText\",\n \"mdxJsxTextTag\",\n \"mdxJsxFlowTag\",\n]);\n\nconst LESS_THAN = 0x3c;\nconst GREATER_THAN = 0x3e;\nconst SLASH = 0x2f;\nconst EXCLAMATION = 0x21;\nconst QUESTION = 0x3f;\n\nfunction isAsciiLetter(unit: number): boolean {\n return (unit >= 0x61 && unit <= 0x7a) || (unit >= 0x41 && unit <= 0x5a);\n}\n\nfunction isTagNameUnit(unit: number): boolean {\n // Deliberately permissive: anything that is not a delimiter belongs to the name. Custom\n // elements (`my-callout`) and member expressions (`Foo.Bar`) must come out whole so that they\n // fail the skip-list membership test rather than being truncated into something that passes.\n return (\n unit !== GREATER_THAN &&\n unit !== SLASH &&\n unit !== 0x20 &&\n unit !== 0x09 &&\n unit !== 0x0a &&\n unit !== 0x0d\n );\n}\n\n/** ASCII-only, because HTML tag names are ASCII case-insensitive and `toLowerCase()` is not. */\nfunction asciiLower(value: string): string {\n let out = \"\";\n for (let i = 0; i < value.length; i += 1) {\n const unit = value.charCodeAt(i);\n out += unit >= 0x41 && unit <= 0x5a ? String.fromCharCode(unit + 0x20) : value[i];\n }\n return out;\n}\n\ninterface RawTag {\n readonly name: string;\n readonly closing: boolean;\n readonly selfClosing: boolean;\n}\n\nfunction readTag(tag: string): RawTag | null {\n if (tag.charCodeAt(0) !== LESS_THAN) return null;\n let i = 1;\n const closing = tag.charCodeAt(i) === SLASH;\n if (closing) i += 1;\n // Comments, declarations and processing instructions carry no element name.\n if (tag.charCodeAt(i) === EXCLAMATION || tag.charCodeAt(i) === QUESTION) return null;\n if (!isAsciiLetter(tag.charCodeAt(i))) return null;\n const nameAt = i;\n while (i < tag.length && isTagNameUnit(tag.charCodeAt(i))) i += 1;\n const selfClosing = tag.charCodeAt(tag.length - 2) === SLASH;\n return { name: tag.slice(nameAt, i), closing, selfClosing };\n}\n\n/**\n * modes.md 3.7: raw HTML is \"handed to the html skip list of 3.6\". Inline raw HTML reaches the\n * tokenizer as isolated tags with ordinary markdown content between them, so honouring the\n * subtree rule means tracking which skipped element is currently open. JSX names are compared\n * case-sensitively (`<Code>` is a component, `<code>` is an element); HTML names are not.\n */\nfunction updateElementStack(stack: string[], tag: string, caseSensitive: boolean): void {\n const parsed = readTag(tag);\n if (parsed === null) return;\n const name = caseSensitive ? parsed.name : asciiLower(parsed.name);\n if (parsed.closing) {\n if (stack[stack.length - 1] === name) stack.pop();\n return;\n }\n if (!parsed.selfClosing && isSkippedElement(name)) stack.push(name);\n}\n\nfunction tokenize(source: string, extensions: readonly Extension[]): Event[] {\n return postprocess(\n parse({ extensions: [...extensions] })\n .document()\n .write(preprocess()(source, null, true)),\n );\n}\n\n/**\n * modes.md 3.7.1. The dialect is the caller's, never detected: `\"commonmark\"` is CommonMark 0.31\n * plus GFM, `\"mdx\"` is the same minus indented code blocks and `<…>` autolinks, plus JSX and\n * `{…}` expression containers. Both enable frontmatter and GFM, which 3.7.2 makes normative —\n * §4's promise that table alignment rows survive is empty unless tables are recognised at all.\n */\nexport function resolveDialect(dialect: Dialect | undefined): Dialect {\n if (dialect === \"commonmark\" || dialect === \"mdx\") return dialect;\n if (dialect === undefined) {\n throw new PolytypoError(\n \"POLYTYPO_INVALID_DIALECT\",\n 'Mode \"markdown\" requires a dialect. Expected \"commonmark\" or \"mdx\"; there is no default.',\n );\n }\n throw new PolytypoError(\n \"POLYTYPO_INVALID_DIALECT\",\n `Unknown dialect \"${String(dialect)}\". Expected \"commonmark\" or \"mdx\".`,\n );\n}\n\nfunction extensionsFor(dialect: Dialect): Extension[] {\n return dialect === \"mdx\" ? [frontmatter(), gfm(), mdxjs()] : [frontmatter(), gfm()];\n}\n\nexport function markdownSpans(source: string, dialect: Dialect): Span[] {\n const events = wrapParserErrors(dialect, () => tokenize(source, extensionsFor(dialect)));\n const spans: Span[] = [];\n const elementStack: string[] = [];\n let skipDepth = 0;\n\n for (const [kind, token] of events) {\n const type = token.type;\n\n if (SKIPPED_TOKEN_TYPES.has(type)) {\n skipDepth += kind === \"enter\" ? 1 : -1;\n continue;\n }\n\n if (RAW_TAG_TOKEN_TYPES.has(type)) {\n if (kind === \"enter\") {\n updateElementStack(\n elementStack,\n source.slice(token.start.offset, token.end.offset),\n type !== \"htmlText\",\n );\n }\n skipDepth += kind === \"enter\" ? 1 : -1;\n continue;\n }\n\n // An HTML block is handed to the `html` extractor rather than skipped whole, so that the\n // prose inside `<div>…</div>` is typeset while the markup is not.\n if (type === \"htmlFlow\") {\n if (kind === \"enter\" && skipDepth === 0 && elementStack.length === 0) {\n for (const span of htmlFragmentSpans(\n source.slice(token.start.offset, token.end.offset),\n token.start.offset,\n )) {\n spans.push(span);\n }\n }\n skipDepth += kind === \"enter\" ? 1 : -1;\n continue;\n }\n\n if (kind === \"enter\" && type === \"data\" && skipDepth === 0 && elementStack.length === 0) {\n spans.push({ start: token.start.offset, end: token.end.offset });\n }\n }\n\n return spans;\n}\n","import { markdownSpans, resolveDialect } from \"../modes/markdown.js\";\nimport type { Options } from \"../types.js\";\nimport { getLocaleData } from \"./locale.js\";\nimport { planRules } from \"./rule-runner.js\";\nimport { runOverSpans } from \"./span-runner.js\";\n\n/**\n * `markdown` mode only. Imports the Micromark/MDX stack and `parse5` (via `../modes/markdown.js`\n * importing `../modes/html.js` for normative embedded-HTML handling, modes.md 3.7) — both are\n * legitimately reachable from `polytypo/markdown` (AUDIT_REMEDIATION_AND_RELEASE_PLAN.md 5.1).\n *\n * Validation order — `planRules`, then `getLocaleData`, then `resolveDialect`/parsing — mirrors\n * the pre-Stage-5 aggregate `runPipeline` exactly: an unknown-rule error wins over an\n * unknown-locale error, which wins over a missing/invalid dialect, which wins over a parse\n * failure. All four are public, tested behaviour this refactor was not authorised to change.\n */\nexport function runMarkdownPipeline(input: string, options: Partial<Options>): string {\n const planned = planRules(options.rules);\n const locale = getLocaleData(options.locale);\n const dialect = resolveDialect(options.dialect);\n const spans = markdownSpans(input, dialect);\n return runOverSpans(input, spans, planned, locale, \"markdown\");\n}\n"]}
@@ -0,0 +1,17 @@
1
+ import {
2
+ PolytypoError
3
+ } from "./chunk-47XAYIKV.js";
4
+
5
+ // src/engine/assert-fixed-mode.ts
6
+ function assertFixedMode(mode, fixed, entryPoint) {
7
+ if (mode === void 0 || mode === fixed) return;
8
+ throw new PolytypoError(
9
+ "POLYTYPO_INVALID_MODE",
10
+ `"${entryPoint}" only supports mode "${fixed}". Received "${String(mode)}" \u2014 import from "polytypo" for the other modes, or omit \`mode\` here.`
11
+ );
12
+ }
13
+
14
+ export {
15
+ assertFixedMode
16
+ };
17
+ //# sourceMappingURL=chunk-MMU4UU46.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/engine/assert-fixed-mode.ts"],"sourcesContent":["import { PolytypoError } from \"../errors.js\";\nimport type { Mode } from \"../types.js\";\n\n/**\n * `polytypo/text`, `polytypo/html` and `polytypo/markdown` each fix `mode` at the type level by\n * omitting it from their Options type (AUDIT_REMEDIATION_AND_RELEASE_PLAN.md 5.1, criterion 6).\n * A plain-JS caller — or a TypeScript caller passing a wider-typed variable, which excess-property\n * checking does not catch — can still supply a conflicting `mode` at runtime. That is rejected\n * explicitly here, never silently ignored or overridden.\n */\nexport function assertFixedMode(mode: unknown, fixed: Mode, entryPoint: string): void {\n if (mode === undefined || mode === fixed) return;\n throw new PolytypoError(\n \"POLYTYPO_INVALID_MODE\",\n `\"${entryPoint}\" only supports mode \"${fixed}\". Received \"${String(mode)}\" — ` +\n `import from \"polytypo\" for the other modes, or omit \\`mode\\` here.`,\n );\n}\n"],"mappings":";;;;;AAUO,SAAS,gBAAgB,MAAe,OAAa,YAA0B;AACpF,MAAI,SAAS,UAAa,SAAS,MAAO;AAC1C,QAAM,IAAI;AAAA,IACR;AAAA,IACA,IAAI,UAAU,yBAAyB,KAAK,gBAAgB,OAAO,IAAI,CAAC;AAAA,EAE1E;AACF;","names":[]}