@bwthomas/outline-numbering 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Blake Thomas
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,147 @@
1
+ # @bwthomas/outline-numbering
2
+
3
+ Framework-agnostic ProseMirror plugin (with Tiptap wrapper) for nested ordered-list numbering with pluggable strategies.
4
+
5
+ - **Alphanumeric** (Harvard / Purdue OWL) — `I. A. 1. a.`
6
+ - **Decimal** — `1. 2. 3.` at every depth (pair with CSS counters for `1.1.1.` composition)
7
+ - **Legal** — `I. A. 1. a. (1) (a) (i)` across 7 levels
8
+ - **Arabic flat** — plain numbered lists
9
+ - **Lower Roman flat** — `i. ii. iii.`
10
+ - **Custom** — any `(counter, depth) → string` you like (emoji, CJK, whatever)
11
+
12
+ ## Install
13
+
14
+ ```sh
15
+ npm install @bwthomas/outline-numbering
16
+ ```
17
+
18
+ Peer deps: `prosemirror-state`, `prosemirror-view`. `@tiptap/core` is required only if you use the Tiptap wrapper.
19
+
20
+ ## Usage
21
+
22
+ ### Tiptap
23
+
24
+ ```ts
25
+ import { Editor } from '@tiptap/core';
26
+ import StarterKit from '@tiptap/starter-kit';
27
+ import { OutlineNumbering } from '@bwthomas/outline-numbering/tiptap';
28
+ import { decimalStrategy } from '@bwthomas/outline-numbering';
29
+
30
+ new Editor({
31
+ extensions: [
32
+ StarterKit,
33
+ OutlineNumbering.configure({ strategy: decimalStrategy }),
34
+ ],
35
+ });
36
+ ```
37
+
38
+ ### Raw ProseMirror
39
+
40
+ ```ts
41
+ import { EditorState } from 'prosemirror-state';
42
+ import { outlineNumberingPlugin, alphanumericStrategy } from '@bwthomas/outline-numbering';
43
+
44
+ const state = EditorState.create({
45
+ doc: myDoc,
46
+ plugins: [
47
+ outlineNumberingPlugin({ strategy: alphanumericStrategy }),
48
+ ...otherPlugins,
49
+ ],
50
+ });
51
+ ```
52
+
53
+ ### CSS
54
+
55
+ The plugin only attaches data attributes. Style the markers yourself:
56
+
57
+ ```css
58
+ ol li[data-outline-marker] {
59
+ position: relative;
60
+ padding-left: 2.5em;
61
+ list-style: none;
62
+ }
63
+
64
+ ol li[data-outline-marker]::before {
65
+ content: attr(data-outline-marker);
66
+ position: absolute;
67
+ left: 0;
68
+ width: 2em;
69
+ text-align: right;
70
+ opacity: 0.8;
71
+ }
72
+ ```
73
+
74
+ ## Strategies
75
+
76
+ ```ts
77
+ import {
78
+ alphanumericStrategy, // I. A. 1. a. — the default
79
+ harvardStrategy, // alias for alphanumericStrategy
80
+ purdueOwlStrategy, // alias for alphanumericStrategy
81
+ decimalStrategy, // 1. at every depth
82
+ legalStrategy, // I. A. 1. a. (1) (a) (i) over 7 levels
83
+ arabicStrategy, // 1. at every depth
84
+ lowerRomanStrategy, // i. at every depth
85
+ } from '@bwthomas/outline-numbering';
86
+ ```
87
+
88
+ ### Custom strategies
89
+
90
+ ```ts
91
+ import type { OutlineNumberingStrategy } from '@bwthomas/outline-numbering';
92
+
93
+ const emojiStrategy: OutlineNumberingStrategy = {
94
+ name: 'emoji',
95
+ format(counter, depth) {
96
+ const glyphs = ['🎯', '✦', '🔹', '▸'];
97
+ return `${glyphs[depth % glyphs.length]} `;
98
+ },
99
+ };
100
+ ```
101
+
102
+ The `format` function must be pure. It's called once per list item during every walk of the document.
103
+
104
+ ## Options
105
+
106
+ ```ts
107
+ outlineNumberingPlugin({
108
+ strategy: alphanumericStrategy,
109
+ descendThroughContainers: true,
110
+ });
111
+ ```
112
+
113
+ - **`strategy`** — any `OutlineNumberingStrategy`. Default: `alphanumericStrategy`.
114
+ - **`descendThroughContainers`** — when `true` (default), ordered lists nested inside non-ordered containers (bullet lists, blockquotes, custom blocks) within a list item are discovered and numbered one level deeper than the enclosing item. When `false`, only ordered lists that are direct children of a list item are walked.
115
+
116
+ ## API
117
+
118
+ ```ts
119
+ // Framework-agnostic
120
+ import {
121
+ outlineNumberingPlugin, // (options?) => Plugin<DecorationSet>
122
+ computeDecorations, // (doc, strategy, descendThroughContainers?) => DecorationSet
123
+ OUTLINE_NUMBERING_KEY, // PluginKey — use to read plugin state from other plugins
124
+ OutlineNumberingStrategy,
125
+ OutlineNumberingPluginOptions,
126
+ toRoman,
127
+ toLetter,
128
+ // ...all named strategies
129
+ } from '@bwthomas/outline-numbering';
130
+
131
+ // Tiptap wrapper
132
+ import { OutlineNumbering, OutlineNumberingOptions } from '@bwthomas/outline-numbering/tiptap';
133
+ ```
134
+
135
+ ## Things to keep in mind if you fork this
136
+
137
+ Short list of conventions worth preserving if you take this in a different direction:
138
+
139
+ - **Support both raw ProseMirror and Tiptap from a single package.** The main entry (`./`) is framework-neutral; the Tiptap wrapper lives at the `/tiptap` subpath. `@tiptap/core` is declared as an optional peer via `peerDependenciesMeta`, so raw-PM users don't get pulled into the Tiptap dep tree. Keep this split if you keep the repo; drop it only if you deliberately commit to one framework.
140
+ - **Strategies are pure.** `format(counter, depth) → string`, same inputs → same output, no closures over mutable state. The plugin invokes them during a walk and assumes no side effects.
141
+ - **Keep the plugin render-only.** It attaches data attributes; it never manipulates the document or dispatches transactions. That's what keeps it composable with collaborative editing (Yjs) and undo/redo — the walker runs against the current doc and produces decorations, full stop.
142
+ - **Alphanumeric is the canonical name; `harvardStrategy` / `purdueOwlStrategy` are aliases.** If you add more, prefer the technical/neutral name as primary and informal names as aliases.
143
+ - **Future: consider wrappers for Lexical, Slate, other editor frameworks.** The walker is framework-agnostic in principle — only the plugin lifecycle differs.
144
+
145
+ ## License
146
+
147
+ MIT — see [LICENSE](./LICENSE).
package/dist/index.cjs ADDED
@@ -0,0 +1,190 @@
1
+ 'use strict';
2
+
3
+ var prosemirrorState = require('prosemirror-state');
4
+ var prosemirrorView = require('prosemirror-view');
5
+
6
+ // src/plugin.ts
7
+
8
+ // src/strategies.ts
9
+ function toRoman(n) {
10
+ const pairs = [
11
+ [1e3, "M"],
12
+ [900, "CM"],
13
+ [500, "D"],
14
+ [400, "CD"],
15
+ [100, "C"],
16
+ [90, "XC"],
17
+ [50, "L"],
18
+ [40, "XL"],
19
+ [10, "X"],
20
+ [9, "IX"],
21
+ [5, "V"],
22
+ [4, "IV"],
23
+ [1, "I"]
24
+ ];
25
+ let result = "";
26
+ for (const [value, symbol] of pairs) {
27
+ while (n >= value) {
28
+ result += symbol;
29
+ n -= value;
30
+ }
31
+ }
32
+ return result;
33
+ }
34
+ function toLetter(n, uppercase) {
35
+ let result = "";
36
+ while (n > 0) {
37
+ n--;
38
+ const base = uppercase ? 65 : 97;
39
+ result = String.fromCharCode(base + n % 26) + result;
40
+ n = Math.floor(n / 26);
41
+ }
42
+ return result;
43
+ }
44
+ var alphanumericStrategy = {
45
+ name: "alphanumeric",
46
+ format(counter, depth) {
47
+ const phase = depth % 4;
48
+ switch (phase) {
49
+ case 0:
50
+ return toRoman(counter) + ".";
51
+ case 1:
52
+ return toLetter(counter, true) + ".";
53
+ case 2:
54
+ return counter.toString() + ".";
55
+ case 3:
56
+ return toLetter(counter, false) + ".";
57
+ default:
58
+ return counter.toString() + ".";
59
+ }
60
+ }
61
+ };
62
+ var harvardStrategy = alphanumericStrategy;
63
+ var purdueOwlStrategy = alphanumericStrategy;
64
+ var decimalStrategy = {
65
+ name: "decimal",
66
+ format(counter) {
67
+ return counter.toString() + ".";
68
+ }
69
+ };
70
+ var legalStrategy = {
71
+ name: "legal",
72
+ format(counter, depth) {
73
+ const phase = depth % 7;
74
+ switch (phase) {
75
+ case 0:
76
+ return toRoman(counter) + ".";
77
+ case 1:
78
+ return toLetter(counter, true) + ".";
79
+ case 2:
80
+ return counter.toString() + ".";
81
+ case 3:
82
+ return toLetter(counter, false) + ".";
83
+ case 4:
84
+ return "(" + counter.toString() + ")";
85
+ case 5:
86
+ return "(" + toLetter(counter, false) + ")";
87
+ case 6:
88
+ return "(" + toRoman(counter).toLowerCase() + ")";
89
+ default:
90
+ return counter.toString() + ".";
91
+ }
92
+ }
93
+ };
94
+ var arabicStrategy = {
95
+ name: "arabic",
96
+ format(counter) {
97
+ return counter.toString() + ".";
98
+ }
99
+ };
100
+ var lowerRomanStrategy = {
101
+ name: "lower-roman",
102
+ format(counter) {
103
+ return toRoman(counter).toLowerCase() + ".";
104
+ }
105
+ };
106
+
107
+ // src/plugin.ts
108
+ var OUTLINE_NUMBERING_KEY = new prosemirrorState.PluginKey("outlineNumbering");
109
+ function outlineNumberingPlugin(options = {}) {
110
+ const strategy = options.strategy ?? alphanumericStrategy;
111
+ const descendThroughContainers = options.descendThroughContainers ?? true;
112
+ return new prosemirrorState.Plugin({
113
+ key: OUTLINE_NUMBERING_KEY,
114
+ state: {
115
+ init(_, { doc }) {
116
+ return computeDecorations(doc, strategy, descendThroughContainers);
117
+ },
118
+ apply(tr, decorationSet) {
119
+ if (tr.docChanged) {
120
+ return computeDecorations(tr.doc, strategy, descendThroughContainers);
121
+ }
122
+ return decorationSet.map(tr.mapping, tr.doc);
123
+ }
124
+ },
125
+ props: {
126
+ decorations(state) {
127
+ return this.getState(state);
128
+ }
129
+ }
130
+ });
131
+ }
132
+ function computeDecorations(doc, strategy, descendThroughContainers = true) {
133
+ const decorations = [];
134
+ function walk(node, pos, depth, insideListItem) {
135
+ if (node.type.name === "orderedList") {
136
+ walkOrderedList(node, pos, depth);
137
+ return;
138
+ }
139
+ if (insideListItem && !descendThroughContainers) return;
140
+ if (!node.isBlock || node.isLeaf) return;
141
+ const offset = pos + (node.type.name === "doc" ? 0 : 1);
142
+ let childOffset = 0;
143
+ node.forEach((child) => {
144
+ walk(child, offset + childOffset, depth, insideListItem);
145
+ childOffset += child.nodeSize;
146
+ });
147
+ }
148
+ function walkOrderedList(node, pos, depth) {
149
+ const offset = pos + 1;
150
+ let counter = 0;
151
+ let childOffset = 0;
152
+ node.forEach((child) => {
153
+ if (child.type.name !== "listItem") {
154
+ childOffset += child.nodeSize;
155
+ return;
156
+ }
157
+ counter++;
158
+ const itemPos = offset + childOffset;
159
+ decorations.push(
160
+ prosemirrorView.Decoration.node(itemPos, itemPos + child.nodeSize, {
161
+ "data-outline-depth": String(depth),
162
+ "data-outline-marker": strategy.format(counter, depth)
163
+ })
164
+ );
165
+ let grandOffset = itemPos + 1;
166
+ child.forEach((grandchild) => {
167
+ walk(grandchild, grandOffset, depth + 1, true);
168
+ grandOffset += grandchild.nodeSize;
169
+ });
170
+ childOffset += child.nodeSize;
171
+ });
172
+ }
173
+ walk(doc, 0, 0, false);
174
+ return prosemirrorView.DecorationSet.create(doc, decorations);
175
+ }
176
+
177
+ exports.OUTLINE_NUMBERING_KEY = OUTLINE_NUMBERING_KEY;
178
+ exports.alphanumericStrategy = alphanumericStrategy;
179
+ exports.arabicStrategy = arabicStrategy;
180
+ exports.computeDecorations = computeDecorations;
181
+ exports.decimalStrategy = decimalStrategy;
182
+ exports.harvardStrategy = harvardStrategy;
183
+ exports.legalStrategy = legalStrategy;
184
+ exports.lowerRomanStrategy = lowerRomanStrategy;
185
+ exports.outlineNumberingPlugin = outlineNumberingPlugin;
186
+ exports.purdueOwlStrategy = purdueOwlStrategy;
187
+ exports.toLetter = toLetter;
188
+ exports.toRoman = toRoman;
189
+ //# sourceMappingURL=index.cjs.map
190
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/strategies.ts","../src/plugin.ts"],"names":["PluginKey","Plugin","Decoration","DecorationSet"],"mappings":";;;;;;;;AASO,SAAS,QAAQ,CAAA,EAAmB;AACzC,EAAA,MAAM,KAAA,GAAkD;AAAA,IACtD,CAAC,KAAM,GAAG,CAAA;AAAA,IAAG,CAAC,KAAK,IAAI,CAAA;AAAA,IAAG,CAAC,KAAK,GAAG,CAAA;AAAA,IAAG,CAAC,KAAK,IAAI,CAAA;AAAA,IAChD,CAAC,KAAK,GAAG,CAAA;AAAA,IAAG,CAAC,IAAI,IAAI,CAAA;AAAA,IAAG,CAAC,IAAI,GAAG,CAAA;AAAA,IAAG,CAAC,IAAI,IAAI,CAAA;AAAA,IAC5C,CAAC,IAAI,GAAG,CAAA;AAAA,IAAG,CAAC,GAAG,IAAI,CAAA;AAAA,IAAG,CAAC,GAAG,GAAG,CAAA;AAAA,IAAG,CAAC,GAAG,IAAI,CAAA;AAAA,IAAG,CAAC,GAAG,GAAG;AAAA,GACpD;AACA,EAAA,IAAI,MAAA,GAAS,EAAA;AACb,EAAA,KAAA,MAAW,CAAC,KAAA,EAAO,MAAM,CAAA,IAAK,KAAA,EAAO;AACnC,IAAA,OAAO,KAAK,KAAA,EAAO;AACjB,MAAA,MAAA,IAAU,MAAA;AACV,MAAA,CAAA,IAAK,KAAA;AAAA,IACP;AAAA,EACF;AACA,EAAA,OAAO,MAAA;AACT;AAEO,SAAS,QAAA,CAAS,GAAW,SAAA,EAA4B;AAC9D,EAAA,IAAI,MAAA,GAAS,EAAA;AACb,EAAA,OAAO,IAAI,CAAA,EAAG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A,WAAA,IAAe,KAAA,CAAM,QAAA;AAAA,IACvB,CAAC,CAAA;AAAA,EACH;AAEA,EAAA,IAAA,CAAK,GAAA,EAAK,CAAA,EAAG,CAAA,EAAG,KAAK,CAAA;AACrB,EAAA,OAAOC,6BAAA,CAAc,MAAA,CAAO,GAAA,EAAK,WAAW,CAAA;AAC9C","file":"index.cjs","sourcesContent":["/**\n * Built-in numbering strategies.\n *\n * Each strategy is a pure function of (counter, depth) → string. Consumers can\n * use these directly or implement their own (emoji markers, CJK ordinals,\n * custom cycles, etc.).\n */\nimport type { OutlineNumberingStrategy } from './plugin';\n\nexport function toRoman(n: number): string {\n const pairs: ReadonlyArray<readonly [number, string]> = [\n [1000, 'M'], [900, 'CM'], [500, 'D'], [400, 'CD'],\n [100, 'C'], [90, 'XC'], [50, 'L'], [40, 'XL'],\n [10, 'X'], [9, 'IX'], [5, 'V'], [4, 'IV'], [1, 'I'],\n ];\n let result = '';\n for (const [value, symbol] of pairs) {\n while (n >= value) {\n result += symbol;\n n -= value;\n }\n }\n return result;\n}\n\nexport function toLetter(n: number, uppercase: boolean): string {\n let result = '';\n while (n > 0) {\n n--;\n const base = uppercase ? 65 : 97;\n result = String.fromCharCode(base + (n % 26)) + result;\n n = Math.floor(n / 26);\n }\n return result;\n}\n\n/**\n * Alphanumeric outline (also known as \"Harvard outline\").\n * depth 0 → Roman (I, II, III)\n * depth 1 → uppercase letter (A, B, C)\n * depth 2 → Arabic (1, 2, 3)\n * depth 3 → lowercase letter (a, b, c)\n * depth 4+ → cycles back to depth 0\n *\n * Canonical form documented by Purdue OWL, MLA, and most US writing style\n * guides.\n */\nexport const alphanumericStrategy: OutlineNumberingStrategy = {\n name: 'alphanumeric',\n format(counter, depth) {\n const phase = depth % 4;\n switch (phase) {\n case 0: return toRoman(counter) + '.';\n case 1: return toLetter(counter, true) + '.';\n case 2: return counter.toString() + '.';\n case 3: return toLetter(counter, false) + '.';\n default: return counter.toString() + '.';\n }\n },\n};\n\n/**\n * Alias for `alphanumericStrategy`. \"Harvard outline\" is a common informal\n * name, though \"Harvard\" in academic/British contexts more commonly denotes\n * citation style — if that ambiguity bothers you, prefer\n * `alphanumericStrategy`.\n */\nexport const harvardStrategy = alphanumericStrategy;\n\n/**\n * Alias for `alphanumericStrategy`. Purdue OWL (Online Writing Lab) is the\n * most widely cited documentation of this scheme and the first reference a\n * lot of writers encounter it through.\n */\nexport const purdueOwlStrategy = alphanumericStrategy;\n\n/**\n * Decimal outline (ISO 2145, IETF).\n * depth 0 → 1., 2., 3.\n * depth 1 → 1.1., 1.2., 2.1.\n * depth 2 → 1.1.1., 1.1.2.\n * ... and so on, indefinitely.\n *\n * Used in technical documentation, engineering reports, software\n * specifications, and European academic writing.\n *\n * Note: the strategy interface does not see the full ancestor chain — the\n * plugin calls `format(counter, depth)` with only the item's own counter.\n * Proper decimal numbering (e.g. \"1.2.3\") requires ancestor context, so this\n * strategy emits a trailing-level marker only (\"3.\" at depth 2). If you need\n * full decimal prefixes, wire them through a custom CSS pseudo-element using\n * `counter-reset` / `counters(ol, \".\")` instead.\n */\nexport const decimalStrategy: OutlineNumberingStrategy = {\n name: 'decimal',\n format(counter) {\n return counter.toString() + '.';\n },\n};\n\n/**\n * Legal / extended alphanumeric outline.\n * depth 0 → I., II., III.\n * depth 1 → A., B., C.\n * depth 2 → 1., 2., 3.\n * depth 3 → a., b., c.\n * depth 4 → (1), (2), (3)\n * depth 5 → (a), (b), (c)\n * depth 6 → (i), (ii), (iii)\n * depth 7+ → cycles back to depth 0\n *\n * Common in US legal writing (briefs, bylaws, statutes) and full-depth\n * academic outlines.\n */\nexport const legalStrategy: OutlineNumberingStrategy = {\n name: 'legal',\n format(counter, depth) {\n const phase = depth % 7;\n switch (phase) {\n case 0: return toRoman(counter) + '.';\n case 1: return toLetter(counter, true) + '.';\n case 2: return counter.toString() + '.';\n case 3: return toLetter(counter, false) + '.';\n case 4: return '(' + counter.toString() + ')';\n case 5: return '(' + toLetter(counter, false) + ')';\n case 6: return '(' + toRoman(counter).toLowerCase() + ')';\n default: return counter.toString() + '.';\n }\n },\n};\n\n/**\n * Flat Arabic numerals at every depth: 1., 2., 3. — no depth awareness.\n * Useful for simple numbered lists or as a building block for custom\n * strategies.\n */\nexport const arabicStrategy: OutlineNumberingStrategy = {\n name: 'arabic',\n format(counter) {\n return counter.toString() + '.';\n },\n};\n\n/**\n * Flat lowercase Roman numerals at every depth: i., ii., iii. — no depth\n * awareness. Matches CSS `list-style-type: lower-roman`. Rare as a root\n * outline style; useful for prefaces, appendices, or as a building block.\n */\nexport const lowerRomanStrategy: OutlineNumberingStrategy = {\n name: 'lower-roman',\n format(counter) {\n return toRoman(counter).toLowerCase() + '.';\n },\n};\n","/**\n * Framework-agnostic ProseMirror plugin for nested ordered-list numbering.\n *\n * The plugin walks the document, counts items per nesting level, and attaches\n * `data-outline-depth` + `data-outline-marker` decorations to each list item.\n * The marker string itself is produced by the caller-supplied strategy, so\n * consumers can render Harvard (I/A/1/a), decimal (1.1.1), legal, emoji, CJK,\n * or any other custom numbering scheme.\n *\n * Consumers turn the attributes into visible markers in CSS, typically via\n * `content: attr(data-outline-marker)` on a `::before` pseudo-element.\n */\nimport { Plugin, PluginKey } from 'prosemirror-state';\nimport { Decoration, DecorationSet } from 'prosemirror-view';\nimport { alphanumericStrategy } from './strategies';\n\n/**\n * Produces the marker string for a given 1-based `counter` at a given nesting\n * `depth`. Implementations must be pure (same inputs → same output); the\n * plugin invokes the strategy once per list item during a walk.\n */\nexport interface OutlineNumberingStrategy {\n name: string;\n format(counter: number, depth: number): string;\n}\n\nexport interface OutlineNumberingPluginOptions {\n /** Numbering scheme. Defaults to `alphanumericStrategy` (Harvard I/A/1/a). */\n strategy: OutlineNumberingStrategy;\n /**\n * When true (default), nested orderedLists inside non-orderedList containers\n * (bulletList, blockquote, custom blocks) within a listItem are discovered\n * and numbered at one level deeper. When false, only orderedLists that are\n * direct children of a listItem are numbered.\n */\n descendThroughContainers: boolean;\n}\n\n/**\n * Stable plugin key — exposed so other plugins can read the current\n * DecorationSet via `OUTLINE_NUMBERING_KEY.getState(editorState)`.\n */\nexport const OUTLINE_NUMBERING_KEY = new PluginKey<DecorationSet>('outlineNumbering');\n\nexport function outlineNumberingPlugin(\n options: Partial<OutlineNumberingPluginOptions> = {},\n): Plugin<DecorationSet> {\n const strategy = options.strategy ?? alphanumericStrategy;\n const descendThroughContainers = options.descendThroughContainers ?? true;\n\n return new Plugin<DecorationSet>({\n key: OUTLINE_NUMBERING_KEY,\n state: {\n init(_, { doc }) {\n return computeDecorations(doc, strategy, descendThroughContainers);\n },\n apply(tr, decorationSet) {\n if (tr.docChanged) {\n return computeDecorations(tr.doc, strategy, descendThroughContainers);\n }\n return decorationSet.map(tr.mapping, tr.doc);\n },\n },\n props: {\n decorations(state) {\n return this.getState(state);\n },\n },\n });\n}\n\n/**\n * Computes the DecorationSet for a document given a strategy. Exported for\n * programmatic use (tests, custom plugin composition); the plugin itself\n * calls this internally.\n */\nexport function computeDecorations(\n doc: any,\n strategy: OutlineNumberingStrategy,\n descendThroughContainers: boolean = true,\n): DecorationSet {\n const decorations: Decoration[] = [];\n\n function walk(node: any, pos: number, depth: number, insideListItem: boolean) {\n if (node.type.name === 'orderedList') {\n walkOrderedList(node, pos, depth);\n return;\n }\n if (insideListItem && !descendThroughContainers) return;\n if (!node.isBlock || node.isLeaf) return;\n const offset = pos + (node.type.name === 'doc' ? 0 : 1);\n let childOffset = 0;\n node.forEach((child: any) => {\n walk(child, offset + childOffset, depth, insideListItem);\n childOffset += child.nodeSize;\n });\n }\n\n function walkOrderedList(node: any, pos: number, depth: number) {\n const offset = pos + 1;\n let counter = 0;\n let childOffset = 0;\n node.forEach((child: any) => {\n if (child.type.name !== 'listItem') {\n childOffset += child.nodeSize;\n return;\n }\n counter++;\n const itemPos = offset + childOffset;\n decorations.push(\n Decoration.node(itemPos, itemPos + child.nodeSize, {\n 'data-outline-depth': String(depth),\n 'data-outline-marker': strategy.format(counter, depth),\n }),\n );\n\n let grandOffset = itemPos + 1;\n child.forEach((grandchild: any) => {\n walk(grandchild, grandOffset, depth + 1, true);\n grandOffset += grandchild.nodeSize;\n });\n childOffset += child.nodeSize;\n });\n }\n\n walk(doc, 0, 0, false);\n return DecorationSet.create(doc, decorations);\n}\n"]}
@@ -0,0 +1,87 @@
1
+ import { O as OutlineNumberingStrategy } from './plugin-CiYM1OJT.cjs';
2
+ export { a as OUTLINE_NUMBERING_KEY, b as OutlineNumberingPluginOptions, c as computeDecorations, o as outlineNumberingPlugin } from './plugin-CiYM1OJT.cjs';
3
+ import 'prosemirror-state';
4
+ import 'prosemirror-view';
5
+
6
+ /**
7
+ * Built-in numbering strategies.
8
+ *
9
+ * Each strategy is a pure function of (counter, depth) → string. Consumers can
10
+ * use these directly or implement their own (emoji markers, CJK ordinals,
11
+ * custom cycles, etc.).
12
+ */
13
+
14
+ declare function toRoman(n: number): string;
15
+ declare function toLetter(n: number, uppercase: boolean): string;
16
+ /**
17
+ * Alphanumeric outline (also known as "Harvard outline").
18
+ * depth 0 → Roman (I, II, III)
19
+ * depth 1 → uppercase letter (A, B, C)
20
+ * depth 2 → Arabic (1, 2, 3)
21
+ * depth 3 → lowercase letter (a, b, c)
22
+ * depth 4+ → cycles back to depth 0
23
+ *
24
+ * Canonical form documented by Purdue OWL, MLA, and most US writing style
25
+ * guides.
26
+ */
27
+ declare const alphanumericStrategy: OutlineNumberingStrategy;
28
+ /**
29
+ * Alias for `alphanumericStrategy`. "Harvard outline" is a common informal
30
+ * name, though "Harvard" in academic/British contexts more commonly denotes
31
+ * citation style — if that ambiguity bothers you, prefer
32
+ * `alphanumericStrategy`.
33
+ */
34
+ declare const harvardStrategy: OutlineNumberingStrategy;
35
+ /**
36
+ * Alias for `alphanumericStrategy`. Purdue OWL (Online Writing Lab) is the
37
+ * most widely cited documentation of this scheme and the first reference a
38
+ * lot of writers encounter it through.
39
+ */
40
+ declare const purdueOwlStrategy: OutlineNumberingStrategy;
41
+ /**
42
+ * Decimal outline (ISO 2145, IETF).
43
+ * depth 0 → 1., 2., 3.
44
+ * depth 1 → 1.1., 1.2., 2.1.
45
+ * depth 2 → 1.1.1., 1.1.2.
46
+ * ... and so on, indefinitely.
47
+ *
48
+ * Used in technical documentation, engineering reports, software
49
+ * specifications, and European academic writing.
50
+ *
51
+ * Note: the strategy interface does not see the full ancestor chain — the
52
+ * plugin calls `format(counter, depth)` with only the item's own counter.
53
+ * Proper decimal numbering (e.g. "1.2.3") requires ancestor context, so this
54
+ * strategy emits a trailing-level marker only ("3." at depth 2). If you need
55
+ * full decimal prefixes, wire them through a custom CSS pseudo-element using
56
+ * `counter-reset` / `counters(ol, ".")` instead.
57
+ */
58
+ declare const decimalStrategy: OutlineNumberingStrategy;
59
+ /**
60
+ * Legal / extended alphanumeric outline.
61
+ * depth 0 → I., II., III.
62
+ * depth 1 → A., B., C.
63
+ * depth 2 → 1., 2., 3.
64
+ * depth 3 → a., b., c.
65
+ * depth 4 → (1), (2), (3)
66
+ * depth 5 → (a), (b), (c)
67
+ * depth 6 → (i), (ii), (iii)
68
+ * depth 7+ → cycles back to depth 0
69
+ *
70
+ * Common in US legal writing (briefs, bylaws, statutes) and full-depth
71
+ * academic outlines.
72
+ */
73
+ declare const legalStrategy: OutlineNumberingStrategy;
74
+ /**
75
+ * Flat Arabic numerals at every depth: 1., 2., 3. — no depth awareness.
76
+ * Useful for simple numbered lists or as a building block for custom
77
+ * strategies.
78
+ */
79
+ declare const arabicStrategy: OutlineNumberingStrategy;
80
+ /**
81
+ * Flat lowercase Roman numerals at every depth: i., ii., iii. — no depth
82
+ * awareness. Matches CSS `list-style-type: lower-roman`. Rare as a root
83
+ * outline style; useful for prefaces, appendices, or as a building block.
84
+ */
85
+ declare const lowerRomanStrategy: OutlineNumberingStrategy;
86
+
87
+ export { OutlineNumberingStrategy, alphanumericStrategy, arabicStrategy, decimalStrategy, harvardStrategy, legalStrategy, lowerRomanStrategy, purdueOwlStrategy, toLetter, toRoman };
@@ -0,0 +1,87 @@
1
+ import { O as OutlineNumberingStrategy } from './plugin-CiYM1OJT.js';
2
+ export { a as OUTLINE_NUMBERING_KEY, b as OutlineNumberingPluginOptions, c as computeDecorations, o as outlineNumberingPlugin } from './plugin-CiYM1OJT.js';
3
+ import 'prosemirror-state';
4
+ import 'prosemirror-view';
5
+
6
+ /**
7
+ * Built-in numbering strategies.
8
+ *
9
+ * Each strategy is a pure function of (counter, depth) → string. Consumers can
10
+ * use these directly or implement their own (emoji markers, CJK ordinals,
11
+ * custom cycles, etc.).
12
+ */
13
+
14
+ declare function toRoman(n: number): string;
15
+ declare function toLetter(n: number, uppercase: boolean): string;
16
+ /**
17
+ * Alphanumeric outline (also known as "Harvard outline").
18
+ * depth 0 → Roman (I, II, III)
19
+ * depth 1 → uppercase letter (A, B, C)
20
+ * depth 2 → Arabic (1, 2, 3)
21
+ * depth 3 → lowercase letter (a, b, c)
22
+ * depth 4+ → cycles back to depth 0
23
+ *
24
+ * Canonical form documented by Purdue OWL, MLA, and most US writing style
25
+ * guides.
26
+ */
27
+ declare const alphanumericStrategy: OutlineNumberingStrategy;
28
+ /**
29
+ * Alias for `alphanumericStrategy`. "Harvard outline" is a common informal
30
+ * name, though "Harvard" in academic/British contexts more commonly denotes
31
+ * citation style — if that ambiguity bothers you, prefer
32
+ * `alphanumericStrategy`.
33
+ */
34
+ declare const harvardStrategy: OutlineNumberingStrategy;
35
+ /**
36
+ * Alias for `alphanumericStrategy`. Purdue OWL (Online Writing Lab) is the
37
+ * most widely cited documentation of this scheme and the first reference a
38
+ * lot of writers encounter it through.
39
+ */
40
+ declare const purdueOwlStrategy: OutlineNumberingStrategy;
41
+ /**
42
+ * Decimal outline (ISO 2145, IETF).
43
+ * depth 0 → 1., 2., 3.
44
+ * depth 1 → 1.1., 1.2., 2.1.
45
+ * depth 2 → 1.1.1., 1.1.2.
46
+ * ... and so on, indefinitely.
47
+ *
48
+ * Used in technical documentation, engineering reports, software
49
+ * specifications, and European academic writing.
50
+ *
51
+ * Note: the strategy interface does not see the full ancestor chain — the
52
+ * plugin calls `format(counter, depth)` with only the item's own counter.
53
+ * Proper decimal numbering (e.g. "1.2.3") requires ancestor context, so this
54
+ * strategy emits a trailing-level marker only ("3." at depth 2). If you need
55
+ * full decimal prefixes, wire them through a custom CSS pseudo-element using
56
+ * `counter-reset` / `counters(ol, ".")` instead.
57
+ */
58
+ declare const decimalStrategy: OutlineNumberingStrategy;
59
+ /**
60
+ * Legal / extended alphanumeric outline.
61
+ * depth 0 → I., II., III.
62
+ * depth 1 → A., B., C.
63
+ * depth 2 → 1., 2., 3.
64
+ * depth 3 → a., b., c.
65
+ * depth 4 → (1), (2), (3)
66
+ * depth 5 → (a), (b), (c)
67
+ * depth 6 → (i), (ii), (iii)
68
+ * depth 7+ → cycles back to depth 0
69
+ *
70
+ * Common in US legal writing (briefs, bylaws, statutes) and full-depth
71
+ * academic outlines.
72
+ */
73
+ declare const legalStrategy: OutlineNumberingStrategy;
74
+ /**
75
+ * Flat Arabic numerals at every depth: 1., 2., 3. — no depth awareness.
76
+ * Useful for simple numbered lists or as a building block for custom
77
+ * strategies.
78
+ */
79
+ declare const arabicStrategy: OutlineNumberingStrategy;
80
+ /**
81
+ * Flat lowercase Roman numerals at every depth: i., ii., iii. — no depth
82
+ * awareness. Matches CSS `list-style-type: lower-roman`. Rare as a root
83
+ * outline style; useful for prefaces, appendices, or as a building block.
84
+ */
85
+ declare const lowerRomanStrategy: OutlineNumberingStrategy;
86
+
87
+ export { OutlineNumberingStrategy, alphanumericStrategy, arabicStrategy, decimalStrategy, harvardStrategy, legalStrategy, lowerRomanStrategy, purdueOwlStrategy, toLetter, toRoman };