@diplodoc/notes-extension 0.0.0-stage → 0.1.0-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.
Files changed (58) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +105 -2
  3. package/build/cjs/browser/index.d.ts +29 -0
  4. package/build/cjs/browser.js +415 -0
  5. package/build/cjs/browser.js.map +7 -0
  6. package/build/cjs/index.js +457 -0
  7. package/build/cjs/index.js.map +7 -0
  8. package/build/cjs/package.json +1 -0
  9. package/build/cjs/plugin/close.d.ts +7 -0
  10. package/build/cjs/plugin/const.d.ts +19 -0
  11. package/build/cjs/plugin/directive.d.ts +12 -0
  12. package/build/cjs/plugin/index.d.ts +18 -0
  13. package/build/cjs/plugin/plugin.d.ts +15 -0
  14. package/build/cjs/plugin/pure.d.ts +6 -0
  15. package/build/cjs/plugin/recognize.d.ts +26 -0
  16. package/build/cjs/plugin/resources.d.ts +9 -0
  17. package/build/cjs/plugin/transform.d.ts +28 -0
  18. package/build/cjs/plugin/types.d.ts +45 -0
  19. package/build/cjs/plugin.js +380 -0
  20. package/build/cjs/plugin.js.map +7 -0
  21. package/build/cjs/runtime/index.d.ts +1 -0
  22. package/build/esm/browser/index.d.ts +29 -0
  23. package/build/esm/browser.js +391 -0
  24. package/build/esm/browser.js.map +7 -0
  25. package/build/esm/index.js +433 -0
  26. package/build/esm/index.js.map +7 -0
  27. package/build/esm/package.json +1 -0
  28. package/build/esm/plugin/close.d.ts +7 -0
  29. package/build/esm/plugin/const.d.ts +19 -0
  30. package/build/esm/plugin/directive.d.ts +12 -0
  31. package/build/esm/plugin/index.d.ts +18 -0
  32. package/build/esm/plugin/plugin.d.ts +15 -0
  33. package/build/esm/plugin/pure.d.ts +6 -0
  34. package/build/esm/plugin/recognize.d.ts +26 -0
  35. package/build/esm/plugin/resources.d.ts +9 -0
  36. package/build/esm/plugin/transform.d.ts +28 -0
  37. package/build/esm/plugin/types.d.ts +45 -0
  38. package/build/esm/plugin.js +353 -0
  39. package/build/esm/plugin.js.map +7 -0
  40. package/build/esm/runtime/index.d.ts +1 -0
  41. package/build/runtime/index.cjs +1 -0
  42. package/build/runtime/index.css +55 -0
  43. package/build/runtime/index.d.ts +1 -0
  44. package/build/runtime/index.mjs +1 -0
  45. package/build/scss/_notes.scss +87 -0
  46. package/build/types/browser/index.d.ts +29 -0
  47. package/build/types/plugin/close.d.ts +7 -0
  48. package/build/types/plugin/const.d.ts +19 -0
  49. package/build/types/plugin/directive.d.ts +12 -0
  50. package/build/types/plugin/index.d.ts +18 -0
  51. package/build/types/plugin/plugin.d.ts +15 -0
  52. package/build/types/plugin/pure.d.ts +6 -0
  53. package/build/types/plugin/recognize.d.ts +26 -0
  54. package/build/types/plugin/resources.d.ts +9 -0
  55. package/build/types/plugin/transform.d.ts +28 -0
  56. package/build/types/plugin/types.d.ts +45 -0
  57. package/build/types/runtime/index.d.ts +1 -0
  58. package/package.json +96 -4
@@ -0,0 +1,29 @@
1
+ import type { NotesDirectivePlugin, NotesFactoryOptions, NotesOptions, NotesPlugin } from '../plugin/types.js';
2
+ import type { RuntimeOption } from '../plugin/resources.js';
3
+ import { TokenType } from '../plugin/const.js';
4
+ export type TransformOptions = NotesOptions & NotesFactoryOptions & {
5
+ runtime?: RuntimeOption;
6
+ bundle?: false;
7
+ };
8
+ export declare function transform(options?: TransformOptions & {
9
+ directiveSyntax?: 'disabled';
10
+ }): NotesPlugin;
11
+ export declare function transform(options: TransformOptions & {
12
+ directiveSyntax: 'enabled' | 'only';
13
+ }): NotesDirectivePlugin;
14
+ export declare function transform(options: TransformOptions): NotesPlugin | NotesDirectivePlugin;
15
+ export { TokenType };
16
+ export type { NotesOptions, NotesLogger, NotesDirectiveDiagnostic, NotesFactoryOptions, NotesDirectivePlugin, } from '../plugin/types.js';
17
+ declare const _default: {
18
+ transform: typeof transform;
19
+ TokenType: {
20
+ readonly Note: "yfm-note";
21
+ readonly NoteOpen: "yfm_note_open";
22
+ readonly NoteClose: "yfm_note_close";
23
+ readonly NoteTitleOpen: "yfm_note_title_open";
24
+ readonly NoteTitleClose: "yfm_note_title_close";
25
+ readonly NoteContentOpen: "yfm_note_content_open";
26
+ readonly NoteContentClose: "yfm_note_content_close";
27
+ };
28
+ };
29
+ export default _default;
@@ -0,0 +1,7 @@
1
+ import type { MatchTokenFunction, NoteToken, NotesLogger } from './types.js';
2
+ /**
3
+ * Bind the existing close-token search to the host's path formatter.
4
+ * @param formatPath - Plain browser or original terminal path formatting.
5
+ * @returns The existing finite token-search factory.
6
+ */
7
+ export declare function createNestedCloseTokenIdxFactory(formatPath: (path: string) => string): (tokenName: string, matchOpenToken: MatchTokenFunction, matchCloseToken: MatchTokenFunction) => (tokens: NoteToken[], idx: number, path: string, log: NotesLogger) => number | null;
@@ -0,0 +1,19 @@
1
+ export declare const ENV_FLAG_NAME = "has-yfm-notes";
2
+ export declare const DEFAULT_LANG = "ru";
3
+ export type Lang = 'ru' | 'en' | 'ar' | 'cs' | 'fr' | 'es' | 'he' | 'bg' | 'et' | 'el' | 'pt' | 'zh' | 'zh-tw' | 'kk' | 'tr' | 'uz';
4
+ export declare const TITLES: Record<Lang, Record<string, string>>;
5
+ export declare const TokenType: {
6
+ readonly Note: "yfm-note";
7
+ readonly NoteOpen: "yfm_note_open";
8
+ readonly NoteClose: "yfm_note_close";
9
+ readonly NoteTitleOpen: "yfm_note_title_open";
10
+ readonly NoteTitleClose: "yfm_note_title_close";
11
+ readonly NoteContentOpen: "yfm_note_content_open";
12
+ readonly NoteContentClose: "yfm_note_content_close";
13
+ };
14
+ export declare const ClassNames: {
15
+ readonly Note: "yfm-note";
16
+ readonly Accent: "yfm-accent";
17
+ readonly Title: "yfm-note-title";
18
+ readonly Content: "yfm-note-content";
19
+ };
@@ -0,0 +1,12 @@
1
+ import type { BlockContentState, DirectiveBlockState, DirectiveInlineState, DirectiveParserHost } from '@diplodoc/directive';
2
+ import type { NotesDirectiveDiagnostic } from './types.js';
3
+ export type NoteMarker = {
4
+ kind: 'open';
5
+ end: object;
6
+ type: string;
7
+ title: string | undefined;
8
+ contentMap: [number, number];
9
+ } | {
10
+ kind: 'close';
11
+ };
12
+ export declare function installNoteDirective<B extends DirectiveBlockState & BlockContentState<B>, I extends DirectiveInlineState>(md: DirectiveParserHost<B, I>, markers: WeakMap<object, NoteMarker>, onDiagnostic?: (diagnostic: NotesDirectiveDiagnostic) => void): void;
@@ -0,0 +1,18 @@
1
+ import { transform } from './transform.js';
2
+ import { TokenType } from './const.js';
3
+ export { transform, TokenType };
4
+ export type { TransformOptions, NotesTransformPlugin, NotesDirectiveTransformPlugin, PluginOptions, CollectOptions, } from './transform.js';
5
+ export type { NotesOptions, NotesLogger, NotesDirectiveDiagnostic, NotesFactoryOptions, NotesDirectivePlugin, } from './types.js';
6
+ declare const _default: {
7
+ transform: typeof transform;
8
+ TokenType: {
9
+ readonly Note: "yfm-note";
10
+ readonly NoteOpen: "yfm_note_open";
11
+ readonly NoteClose: "yfm_note_close";
12
+ readonly NoteTitleOpen: "yfm_note_title_open";
13
+ readonly NoteTitleClose: "yfm_note_title_close";
14
+ readonly NoteContentOpen: "yfm_note_content_open";
15
+ readonly NoteContentClose: "yfm_note_content_close";
16
+ };
17
+ };
18
+ export default _default;
@@ -0,0 +1,15 @@
1
+ import type { NotesDirectivePlugin, NotesFactoryOptions, NotesPlugin } from './types.js';
2
+ /**
3
+ * Bind existing feature diagnostics to an execution-host path formatter.
4
+ * @param formatPath - Original terminal or plain browser formatting.
5
+ * @param onNote - Optional host resource notification after a real note is created.
6
+ * @returns The unchanged feature callback.
7
+ */
8
+ export declare function createNotesPlugin(formatPath?: (path: string) => string, onNote?: (env: Record<string, unknown>) => void): NotesPlugin;
9
+ export declare function createNotesPlugin(formatPath: ((path: string) => string) | undefined, onNote: ((env: Record<string, unknown>) => void) | undefined, factory: NotesFactoryOptions & {
10
+ directiveSyntax: 'disabled';
11
+ }): NotesPlugin;
12
+ export declare function createNotesPlugin(formatPath: ((path: string) => string) | undefined, onNote: ((env: Record<string, unknown>) => void) | undefined, factory: NotesFactoryOptions & {
13
+ directiveSyntax: 'enabled' | 'only';
14
+ }): NotesDirectivePlugin;
15
+ export declare function createNotesPlugin(formatPath: ((path: string) => string) | undefined, onNote: ((env: Record<string, unknown>) => void) | undefined, factory: NotesFactoryOptions): NotesPlugin | NotesDirectivePlugin;
@@ -0,0 +1,6 @@
1
+ export { createNotesPlugin } from './plugin.js';
2
+ export { TokenType, TITLES, DEFAULT_LANG } from './const.js';
3
+ export type { Lang } from './const.js';
4
+ export type { NoteParser, NoteState, NoteToken, NotesLogger, NotesOptions, NotesPlugin, NotesDirectivePlugin, NotesDirectiveDiagnostic, NotesFactoryOptions, } from './types.js';
5
+ export { recognizeNoteBoundary } from './recognize.js';
6
+ export type { NoteBoundary } from './recognize.js';
@@ -0,0 +1,26 @@
1
+ import type { NoteToken } from './types.js';
2
+ export declare function matchCloseToken(tokens: readonly NoteToken[], i: number): boolean;
3
+ export declare function matchOpenToken(tokens: readonly NoteToken[], i: number): false | RegExpMatchArray | null;
4
+ export declare function matchWrongNotes(tokens: readonly NoteToken[], i: number): false | RegExpMatchArray | null;
5
+ export type NoteBoundary = {
6
+ readonly map: readonly [number, number] | null;
7
+ readonly raw: string;
8
+ } & ({
9
+ readonly kind: 'open';
10
+ readonly type: 'info' | 'tip' | 'warning' | 'alert';
11
+ readonly title: {
12
+ readonly present: false;
13
+ } | {
14
+ readonly present: true;
15
+ readonly raw: string;
16
+ };
17
+ } | {
18
+ readonly kind: 'close' | 'unsupported';
19
+ });
20
+ /**
21
+ * Classify an original core paragraph without modifying it.
22
+ * @param tokens - The original block token array.
23
+ * @param i - The candidate paragraph token index.
24
+ * @returns A copied boundary observation when recognized.
25
+ */
26
+ export declare function recognizeNoteBoundary(tokens: readonly NoteToken[], i: number): NoteBoundary | undefined;
@@ -0,0 +1,9 @@
1
+ import type { NotesOptions } from './types.js';
2
+ export type Runtime = {
3
+ style: string;
4
+ script?: string;
5
+ };
6
+ export type RuntimeOption = false | string | Runtime;
7
+ export declare function normalizeRuntime(runtime?: RuntimeOption, bundle?: boolean): Runtime | false;
8
+ export declare function semanticOptions(defaults: NotesOptions, settings: NotesOptions): NotesOptions;
9
+ export declare function addResources(env: Record<string, unknown>, runtime: Runtime): void;
@@ -0,0 +1,28 @@
1
+ import type { BlockContentState, DirectiveBlockState, DirectiveInlineState, DirectiveParserHost } from '@diplodoc/directive';
2
+ import type { NoteParser, NoteToken, NotesFactoryOptions, NotesOptions } from './types.js';
3
+ import type { RuntimeOption } from './resources.js';
4
+ export type TransformOptions = NotesOptions & NotesFactoryOptions & {
5
+ runtime?: RuntimeOption;
6
+ bundle?: boolean;
7
+ };
8
+ export type PluginOptions = NotesOptions & {
9
+ output?: string;
10
+ };
11
+ export type CollectOptions = NotesOptions & {
12
+ destRoot?: string;
13
+ };
14
+ export interface NotesTransformPlugin {
15
+ <Token extends NoteToken>(md: NoteParser<Token>, settings?: PluginOptions): void;
16
+ collect(input: string, options?: CollectOptions): void;
17
+ }
18
+ export interface NotesDirectiveTransformPlugin {
19
+ <Token extends NoteToken, Block extends DirectiveBlockState & BlockContentState<Block>, Inline extends DirectiveInlineState>(md: NoteParser<Token> & DirectiveParserHost<Block, Inline>, settings?: PluginOptions): void;
20
+ collect(input: string, options?: CollectOptions): void;
21
+ }
22
+ export declare function transform(options?: TransformOptions & {
23
+ directiveSyntax?: 'disabled';
24
+ }): NotesTransformPlugin;
25
+ export declare function transform(options: TransformOptions & {
26
+ directiveSyntax: 'enabled' | 'only';
27
+ }): NotesDirectiveTransformPlugin;
28
+ export declare function transform(options: TransformOptions): NotesTransformPlugin | NotesDirectiveTransformPlugin;
@@ -0,0 +1,45 @@
1
+ import type { BlockContentState, DirectiveBlockState, DirectiveInlineState, DirectiveParserHost } from '@diplodoc/directive';
2
+ export interface NoteToken {
3
+ type: string;
4
+ content: string;
5
+ map: [number, number] | null;
6
+ block: boolean;
7
+ attrSet(name: string, value: string): void;
8
+ }
9
+ export interface NoteState<Token extends NoteToken> {
10
+ tokens: Token[];
11
+ env: Record<string, unknown>;
12
+ Token: new (type: string, tag: string, nesting: -1 | 0 | 1) => Token;
13
+ md: {
14
+ parseInline(source: string, env: Record<string, unknown>): Token[];
15
+ };
16
+ }
17
+ export interface NoteParser<Token extends NoteToken> {
18
+ core: {
19
+ ruler: {
20
+ before(beforeName: string, name: string, rule: (state: NoteState<Token>) => void): void;
21
+ push(name: string, rule: (state: NoteState<Token>) => void): void;
22
+ };
23
+ };
24
+ }
25
+ export type NotesOptions = {
26
+ lang?: string;
27
+ notesAutotitle?: boolean;
28
+ path?: string;
29
+ log?: NotesLogger;
30
+ };
31
+ export interface NotesLogger {
32
+ warn(message: string): void;
33
+ error(message: string): void;
34
+ }
35
+ export type NotesPlugin = <Token extends NoteToken>(md: NoteParser<Token>, options?: NotesOptions) => void;
36
+ export type NotesDirectivePlugin = <Token extends NoteToken, Block extends DirectiveBlockState & BlockContentState<Block>, Inline extends DirectiveInlineState>(md: NoteParser<Token> & DirectiveParserHost<Block, Inline>, options?: NotesOptions) => void;
37
+ export type NotesDirectiveDiagnostic = {
38
+ line: number;
39
+ reason: string;
40
+ };
41
+ export type NotesFactoryOptions = {
42
+ directiveSyntax?: 'disabled' | 'enabled' | 'only';
43
+ onDiagnostic?: (diagnostic: NotesDirectiveDiagnostic) => void;
44
+ };
45
+ export type MatchTokenFunction = (tokens: NoteToken[], index: number) => boolean | RegExpMatchArray | null;
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,98 @@
1
1
  {
2
2
  "name": "@diplodoc/notes-extension",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0-transform5.1",
4
+ "description": "Notes extension for Diplodoc platform",
5
+ "main": "build/cjs/index.js",
6
+ "types": "build/cjs/plugin/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "import": {
10
+ "types": "./build/esm/plugin/index.d.ts",
11
+ "default": "./build/esm/index.js"
12
+ },
13
+ "require": {
14
+ "types": "./build/cjs/plugin/index.d.ts",
15
+ "default": "./build/cjs/index.js"
16
+ }
17
+ },
18
+ "./plugin": {
19
+ "import": {
20
+ "types": "./build/esm/plugin/pure.d.ts",
21
+ "default": "./build/esm/plugin.js"
22
+ },
23
+ "require": {
24
+ "types": "./build/cjs/plugin/pure.d.ts",
25
+ "default": "./build/cjs/plugin.js"
26
+ }
27
+ },
28
+ "./browser": {
29
+ "import": {
30
+ "types": "./build/esm/browser/index.d.ts",
31
+ "default": "./build/esm/browser.js"
32
+ },
33
+ "require": {
34
+ "types": "./build/cjs/browser/index.d.ts",
35
+ "default": "./build/cjs/browser.js"
36
+ }
37
+ },
38
+ "./runtime": {
39
+ "types": "./build/runtime/index.d.ts",
40
+ "import": "./build/runtime/index.mjs",
41
+ "require": "./build/runtime/index.cjs"
42
+ },
43
+ "./runtime/styles": "./build/runtime/index.css",
44
+ "./runtime/styles.css": "./build/runtime/index.css",
45
+ "./scss/notes": "./build/scss/_notes.scss",
46
+ "./package.json": "./package.json"
47
+ },
48
+ "homepage": "https://diplodoc.com/",
49
+ "repository": {
50
+ "type": "git",
51
+ "url": "git+https://github.com/diplodoc-platform/notes-extension.git"
52
+ },
53
+ "bugs": {
54
+ "url": "https://github.com/diplodoc-platform/diplodoc/issues"
55
+ },
56
+ "private": false,
57
+ "author": "",
58
+ "license": "MIT",
59
+ "files": [
60
+ "build"
61
+ ],
62
+ "scripts": {
63
+ "build": "node esbuild/build.mjs",
64
+ "test": "vitest run",
65
+ "typecheck": "tsc --noEmit",
66
+ "test:package": "node scripts/test-package.mjs",
67
+ "prepublishOnly": "npm run lint && npm run typecheck && npm test && npm run build && npm run test:package",
68
+ "lint": "lint && eslint --no-ignore esbuild",
69
+ "lint:fix": "lint fix && eslint --no-ignore esbuild --fix",
70
+ "pre-commit": "lint-staged",
71
+ "prepare": "husky || true",
72
+ "lock": "npm install --no-workspaces --package-lock-only --ignore-scripts"
73
+ },
74
+ "devDependencies": {
75
+ "@diplodoc/infra": "2.3.0",
76
+ "@types/node": "^22.19.11",
77
+ "@typescript-eslint/eslint-plugin": "8.72.1",
78
+ "@typescript-eslint/parser": "8.72.1",
79
+ "esbuild": "0.25.12",
80
+ "husky": "^9.1.7",
81
+ "markdown-it": "15.0.3",
82
+ "playwright": "^1.60.0",
83
+ "sass": "1.97.3",
84
+ "typescript": "6.0.3",
85
+ "vitest": "^3.2.4"
86
+ },
87
+ "module": "build/esm/index.js",
88
+ "peerDependencies": {
89
+ "markdown-it": "^13.0.0 || ^14.0.0 || ^15.0.0"
90
+ },
91
+ "engines": {
92
+ "node": ">=24",
93
+ "npm": ">=11.5.1"
94
+ },
95
+ "dependencies": {
96
+ "@diplodoc/directive": "0.5.0-transform5.2"
97
+ }
98
+ }