nxt-highlightjs 20.0.0 → 21.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.
package/package.json CHANGED
@@ -2,10 +2,13 @@
2
2
  "name": "nxt-highlightjs",
3
3
  "description": "Angular code highlighting directives with optional line numbers and support for SSR",
4
4
  "bugs": "https://github.com/Liquid-JS/nxt-components/issues",
5
- "version": "20.0.0",
5
+ "version": "21.0.0",
6
6
  "license": "MIT",
7
7
  "type": "module",
8
- "repository": "https://github.com/Liquid-JS/nxt-components.git",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/Liquid-JS/nxt-components.git"
11
+ },
9
12
  "homepage": "https://github.com/Liquid-JS/nxt-components/tree/master/packages/highlightjs",
10
13
  "keywords": [
11
14
  "nxt-highlightjs",
@@ -19,34 +22,34 @@
19
22
  "gist"
20
23
  ],
21
24
  "peerDependencies": {
22
- "@angular/cdk": "^20.0.0",
23
- "@angular/common": "^20.0.0",
24
- "@angular/core": "^20.0.0",
25
- "@angular/platform-browser": "^20.0.0",
25
+ "@angular/cdk": "^21.0.0",
26
+ "@angular/common": "^21.0.0",
27
+ "@angular/core": "^21.0.0",
28
+ "@angular/platform-browser": "^21.0.0",
26
29
  "highlight.js": ">=11.11.1",
27
30
  "rxjs": "^7.8.2"
28
31
  },
29
- "dependencies": {
30
- "tslib": "^2.8.1"
31
- },
32
32
  "module": "fesm2022/nxt-highlightjs.mjs",
33
- "typings": "index.d.ts",
33
+ "typings": "types/nxt-highlightjs.d.ts",
34
34
  "exports": {
35
35
  "./package.json": {
36
36
  "default": "./package.json"
37
37
  },
38
38
  ".": {
39
- "types": "./index.d.ts",
39
+ "types": "./types/nxt-highlightjs.d.ts",
40
40
  "default": "./fesm2022/nxt-highlightjs.mjs"
41
41
  },
42
42
  "./extras": {
43
- "types": "./extras/index.d.ts",
43
+ "types": "./types/nxt-highlightjs-extras.d.ts",
44
44
  "default": "./fesm2022/nxt-highlightjs-extras.mjs"
45
45
  },
46
46
  "./line-numbers": {
47
- "types": "./line-numbers/index.d.ts",
47
+ "types": "./types/nxt-highlightjs-line-numbers.d.ts",
48
48
  "default": "./fesm2022/nxt-highlightjs-line-numbers.mjs"
49
49
  }
50
50
  },
51
- "sideEffects": false
51
+ "sideEffects": false,
52
+ "dependencies": {
53
+ "tslib": "^2.3.0"
54
+ }
52
55
  }
@@ -1,7 +1,29 @@
1
1
  import * as i0 from '@angular/core';
2
- import { PipeTransform, InjectionToken, Provider, OnDestroy, EventEmitter } from '@angular/core';
2
+ import { InjectionToken, PipeTransform, Provider, Signal } from '@angular/core';
3
3
  import { Observable } from 'rxjs';
4
+ import * as nxt_highlightjs_extras from 'nxt-highlightjs/extras';
5
+ import { HttpClient } from '@angular/common/http';
6
+ import { RxResourceOptions } from '@angular/core/rxjs-interop';
4
7
 
8
+ /**
9
+ * Injection token used to provide the current location to `codeFromUrl` pipe.
10
+ * Used to handle server-side rendering and to stub out during unit tests.
11
+ */
12
+ declare const NXT_HIGHLIGHT_FILE_LOCATION: InjectionToken<CodeFileLocation>;
13
+ /**
14
+ * @internal
15
+ */
16
+ interface CodeFileLocation {
17
+ formatPathname: (path: string) => string;
18
+ }
19
+ /** @internal */
20
+ declare function CODE_FILE_LOCATION_FACTORY(): {
21
+ formatPathname: (path: string) => string;
22
+ };
23
+
24
+ /**
25
+ * @deprecated use fileResource with `{ formatUrl: true }`
26
+ */
5
27
  declare class CodeFromUrlPipe implements PipeTransform {
6
28
  private readonly location;
7
29
  private readonly loader;
@@ -10,11 +32,15 @@ declare class CodeFromUrlPipe implements PipeTransform {
10
32
  static ɵpipe: i0.ɵɵPipeDeclaration<CodeFromUrlPipe, "codeFromUrl", true>;
11
33
  }
12
34
 
35
+ /** @internal */
13
36
  declare function isUrl(url: string): boolean;
14
37
  interface GistOptions {
15
38
  clientId: string;
16
39
  clientSecret: string;
17
40
  }
41
+ /**
42
+ * @internal
43
+ */
18
44
  declare const NXT_GIST_OPTIONS: InjectionToken<GistOptions>;
19
45
  declare function provideGistOptions(options: GistOptions): Provider[];
20
46
  interface Owner {
@@ -104,37 +130,56 @@ interface Gist {
104
130
  truncated: boolean;
105
131
  }
106
132
 
133
+ /** @internal */
107
134
  declare class CodeLoader {
108
- private readonly http;
109
- private readonly options;
135
+ readonly http: HttpClient;
136
+ readonly options: nxt_highlightjs_extras.GistOptions | null;
137
+ private readonly pendingTasks;
110
138
  /**
111
139
  * Get plus code
112
140
  *
113
141
  * @param id Gist ID
142
+ * @deprecated Use gistResource
114
143
  */
115
144
  getCodeFromGist(id: string): Observable<Gist>;
116
145
  /**
117
146
  * Get code by URL
118
147
  *
119
148
  * @param url File raw link
149
+ * @deprecated Use fileResource
120
150
  */
121
151
  getCodeFromUrl(url: string): Observable<string>;
122
- private fetchFile;
152
+ fetchFile(url: string, options: any): Observable<any>;
123
153
  static ɵfac: i0.ɵɵFactoryDeclaration<CodeLoader, never>;
124
154
  static ɵprov: i0.ɵɵInjectableDeclaration<CodeLoader>;
125
155
  }
156
+ /**
157
+ * Code resource by URL
158
+ *
159
+ * @param url File raw link
160
+ */
161
+ declare function fileResource(url: string | Signal<string>, _options?: Omit<RxResourceOptions<string, string>, 'params' | 'stream'> & {
162
+ formatUrl?: boolean;
163
+ }): i0.ResourceRef<string | undefined>;
164
+ /**
165
+ * Gist resource by id
166
+ *
167
+ * @param id Gist ID
168
+ */
169
+ declare function gistResource(id: string | Signal<string>, options?: Omit<RxResourceOptions<Gist, string>, 'params' | 'stream'>): i0.ResourceRef<Gist | undefined>;
126
170
 
127
- declare class GistDirective implements OnDestroy {
171
+ /**
172
+ * @deprecated use gistResource
173
+ */
174
+ declare class GistDirective {
128
175
  private readonly loader;
129
176
  private readonly pendingTasks;
130
- private readonly cdRef;
131
- private subscription?;
132
- set gist(value: string);
133
- gistLoad: EventEmitter<Gist>;
134
- gistError: EventEmitter<any>;
135
- ngOnDestroy(): void;
177
+ readonly gist: i0.InputSignal<string | undefined>;
178
+ readonly gistLoad: i0.OutputEmitterRef<Gist>;
179
+ readonly gistError: i0.OutputEmitterRef<any>;
180
+ constructor();
136
181
  static ɵfac: i0.ɵɵFactoryDeclaration<GistDirective, never>;
137
- static ɵdir: i0.ɵɵDirectiveDeclaration<GistDirective, "[nxtGist]", never, { "gist": { "alias": "nxtGist"; "required": false; }; }, { "gistLoad": "gistLoad"; "gistError": "gistError"; }, never, never, true, never>;
182
+ static ɵdir: i0.ɵɵDirectiveDeclaration<GistDirective, "[nxtGist]", never, { "gist": { "alias": "nxtGist"; "required": false; "isSignal": true; }; }, { "gistLoad": "gistLoad"; "gistError": "gistError"; }, never, never, true, never>;
138
183
  }
139
184
  declare class GistFilePipe implements PipeTransform {
140
185
  transform(gist?: Gist | null, fileName?: string | null): GistFile | undefined;
@@ -142,11 +187,12 @@ declare class GistFilePipe implements PipeTransform {
142
187
  static ɵpipe: i0.ɵɵPipeDeclaration<GistFilePipe, "gistFile", true>;
143
188
  }
144
189
 
190
+ /** @deprecated use standalone imports */
145
191
  declare class HighlightExstrasModule {
146
192
  static ɵfac: i0.ɵɵFactoryDeclaration<HighlightExstrasModule, never>;
147
193
  static ɵmod: i0.ɵɵNgModuleDeclaration<HighlightExstrasModule, never, [typeof GistDirective, typeof GistFilePipe, typeof CodeFromUrlPipe], [typeof GistDirective, typeof GistFilePipe, typeof CodeFromUrlPipe]>;
148
194
  static ɵinj: i0.ɵɵInjectorDeclaration<HighlightExstrasModule>;
149
195
  }
150
196
 
151
- export { CodeFromUrlPipe, CodeLoader, GistDirective, GistFilePipe, HighlightExstrasModule, NXT_GIST_OPTIONS, isUrl, provideGistOptions };
152
- export type { Gist, GistFile, GistOptions };
197
+ export { CODE_FILE_LOCATION_FACTORY, CodeFromUrlPipe, CodeLoader, GistDirective, GistFilePipe, HighlightExstrasModule, NXT_GIST_OPTIONS, NXT_HIGHLIGHT_FILE_LOCATION, fileResource, gistResource, isUrl, provideGistOptions };
198
+ export type { CodeFileLocation, Gist, GistFile, GistOptions };
@@ -1,9 +1,6 @@
1
+ import { LineNumbersOptions } from 'nxt-highlightjs';
1
2
  import * as _angular_core from '@angular/core';
2
3
 
3
- interface LineNumbersOptions {
4
- startFrom?: number;
5
- singleLine?: boolean;
6
- }
7
4
  declare function activateLineNumbers(document: Document): (code: string, options?: LineNumbersOptions) => string;
8
5
 
9
6
  declare class HighlightLineNumbersDirective {
@@ -20,67 +20,92 @@ interface HighlightJSOptions {
20
20
  }>;
21
21
  themePath?: string;
22
22
  }
23
+ /**
24
+ * @internal
25
+ */
23
26
  declare const NXT_HIGHLIGHT_OPTIONS: InjectionToken<HighlightJSOptions>;
24
27
  declare function provideHighlightOptions(options: HighlightJSOptions): i0.EnvironmentProviders;
25
28
 
26
29
  declare class HighlightJS {
27
30
  private readonly loader;
28
31
  readonly hljs: i0.Signal<HLJSApi | undefined>;
29
- constructor();
30
32
  /**
31
33
  * Core highlighting function. Accepts the code to highlight (string) and a list of options (object)
34
+ *
35
+ * @deprecated use hljs().highlight
32
36
  */
33
37
  highlight(code: string, options: HighlightOptions): Promise<HighlightResult>;
34
38
  /**
35
39
  * Highlighting with language detection.
40
+ *
41
+ * @deprecated use hljs().highlightAuto
36
42
  */
37
43
  highlightAuto(value: string, languageSubset?: string[]): Promise<AutoHighlightResult>;
38
44
  /**
39
45
  * Applies highlighting to a DOM node containing code.
40
46
  * This function is the one to use to apply highlighting dynamically after page load or within initialization code of third-party JavaScript frameworks.
41
47
  * The function uses language detection by default but you can specify the language in the class attribute of the DOM node. See the scopes reference for all available language names and scopes.
48
+ *
49
+ * @deprecated use hljs().highlightElement
42
50
  */
43
51
  highlightElement(element: HTMLElement): Promise<void>;
44
52
  /**
45
53
  * Applies highlighting to all elements on a page matching the configured cssSelector. The default cssSelector value is 'pre code',
46
54
  * which highlights all code blocks. This can be called before or after the page’s onload event has fired.
55
+ *
56
+ * @deprecated use hljs().highlightAll
47
57
  */
48
58
  highlightAll(): Promise<void>;
49
59
  /**
50
60
  * Adds new language to the library under the specified name. Used mostly internally.
51
61
  * The function is passed the hljs object to be able to use common regular expressions defined within it.
62
+ *
63
+ * @deprecated use hljs().registerLanguage
52
64
  */
53
65
  registerLanguage(languageName: string, languageDefinition: LanguageFn): Promise<void>;
54
66
  /**
55
67
  * Removes a language and its aliases from the library. Used mostly internally
68
+ *
69
+ * @deprecated use hljs().unregisterLanguage
56
70
  */
57
71
  unregisterLanguage(languageName: string): Promise<void>;
58
72
  /**
59
73
  * Adds new language alias or aliases to the library for the specified language name defined under languageName key.
74
+ *
75
+ * @deprecated use hljs().registerAliases
60
76
  */
61
77
  registerAliases(alias: string | string[], { languageName }: {
62
78
  languageName: string;
63
79
  }): Promise<void>;
64
80
  /**
65
81
  * @return The languages names list.
82
+ * @deprecated use hljs().listLanguages
66
83
  */
67
84
  listLanguages(): Promise<string[]>;
68
85
  /**
69
86
  * Looks up a language by name or alias.
87
+ *
88
+ * @deprecated use hljs().getLanguage
70
89
  */
71
90
  getLanguage(name: string): Promise<any>;
72
91
  /**
73
92
  * Enables safe mode. This is the default mode, providing the most reliable experience for production usage.
93
+ *
94
+ * @deprecated use hljs().safeMode
74
95
  */
75
96
  safeMode(): Promise<void>;
76
97
  /**
77
98
  * Enables debug/development mode.
99
+ *
100
+ * @deprecated use hljs().debugMode
78
101
  */
79
102
  debugMode(): Promise<void>;
80
103
  /**
81
104
  * Display line numbers
105
+ *
106
+ * @deprecated use hljs().lineNumbersBlock
82
107
  */
83
- lineNumbersBlock(el: HTMLElement, options: LineNumbersOptions): Promise<void>;
108
+ lineNumbersBlock(code: string, options: LineNumbersOptions): Promise<void>;
84
109
  static ɵfac: i0.ɵɵFactoryDeclaration<HighlightJS, never>;
85
110
  static ɵprov: i0.ɵɵInjectableDeclaration<HighlightJS>;
86
111
  }
@@ -92,15 +117,15 @@ declare abstract class HighlightBase {
92
117
  /**
93
118
  * Code to highlight
94
119
  */
95
- abstract code: InputSignal<string | null | undefined>;
120
+ abstract readonly code: InputSignal<string | undefined>;
96
121
  /**
97
122
  * Highlighted result
98
123
  */
99
- abstract highlightResult: WritableSignal<HighlightResult | AutoHighlightResult | undefined>;
124
+ abstract readonly highlightResult: WritableSignal<HighlightResult | AutoHighlightResult | undefined>;
100
125
  /**
101
126
  * Stream that emits when code string is highlighted
102
127
  */
103
- abstract highlighted: OutputEmitterRef<HighlightResult | AutoHighlightResult | undefined>;
128
+ abstract readonly highlighted: OutputEmitterRef<HighlightResult | AutoHighlightResult | undefined>;
104
129
  constructor();
105
130
  protected abstract highlightElement(code: string): HighlightResult | AutoHighlightResult | undefined;
106
131
  private setTextContent;
@@ -113,11 +138,11 @@ declare class HighlightAutoDirective extends HighlightBase {
113
138
  /**
114
139
  * Code to highlight
115
140
  */
116
- code: i0.InputSignal<string | null | undefined>;
141
+ readonly code: i0.InputSignal<string | undefined>;
117
142
  /**
118
143
  * Highlighted result
119
144
  */
120
- highlightResult: i0.WritableSignal<AutoHighlightResult | undefined>;
145
+ readonly highlightResult: i0.WritableSignal<AutoHighlightResult | undefined>;
121
146
  /**
122
147
  * An optional array of language names and aliases restricting detection to only those languages
123
148
  *
@@ -127,7 +152,7 @@ declare class HighlightAutoDirective extends HighlightBase {
127
152
  /**
128
153
  * Stream that emits when code string is highlighted
129
154
  */
130
- highlighted: OutputEmitterRef<AutoHighlightResult>;
155
+ readonly highlighted: i0.OutputEmitterRef<AutoHighlightResult>;
131
156
  protected highlightElement(code: string): AutoHighlightResult | undefined;
132
157
  static ɵfac: i0.ɵɵFactoryDeclaration<HighlightAutoDirective, never>;
133
158
  static ɵdir: i0.ɵɵDirectiveDeclaration<HighlightAutoDirective, "[nxtHighlightAuto]", never, { "code": { "alias": "nxtHighlightAuto"; "required": false; "isSignal": true; }; "languages": { "alias": "languages"; "required": false; "isSignal": true; }; }, { "highlighted": "highlighted"; }, never, never, true, never>;
@@ -137,15 +162,15 @@ declare class HighlightDirective extends HighlightBase {
137
162
  /**
138
163
  * Code to highlight
139
164
  */
140
- code: InputSignal<string | null | undefined>;
165
+ readonly code: i0.InputSignal<string | undefined>;
141
166
  /**
142
167
  * Highlighted result
143
168
  */
144
- highlightResult: i0.WritableSignal<HighlightResult | undefined>;
169
+ readonly highlightResult: i0.WritableSignal<HighlightResult | undefined>;
145
170
  /**
146
171
  * The language name highlight only one language
147
172
  */
148
- readonly language: InputSignal<string>;
173
+ readonly language: i0.InputSignal<string>;
149
174
  /**
150
175
  * An optional flag, when set to true it forces highlighting to finish even in case of detecting
151
176
  * illegal syntax for the language instead of throwing an exception
@@ -154,7 +179,7 @@ declare class HighlightDirective extends HighlightBase {
154
179
  /**
155
180
  * Stream that emits when code string is highlighted
156
181
  */
157
- highlighted: i0.OutputEmitterRef<HighlightResult>;
182
+ readonly highlighted: i0.OutputEmitterRef<HighlightResult>;
158
183
  highlightElement(code: string): HighlightResult | undefined;
159
184
  static ɵfac: i0.ɵɵFactoryDeclaration<HighlightDirective, never>;
160
185
  static ɵdir: i0.ɵɵDirectiveDeclaration<HighlightDirective, "[nxtHighlight]", never, { "code": { "alias": "nxtHighlight"; "required": false; "isSignal": true; }; "language": { "alias": "language"; "required": true; "isSignal": true; }; "ignoreIllegals": { "alias": "ignoreIllegals"; "required": false; "isSignal": true; }; }, { "highlighted": "highlighted"; }, never, never, true, never>;
@@ -165,7 +190,12 @@ declare class HighlightLoader {
165
190
  private readonly options;
166
191
  private readonly pendingTasks;
167
192
  private _t;
168
- readonly ready: Promise<HLJSApi>;
193
+ readonly hljs: i0.Resource<HLJSApi | undefined>;
194
+ private readonly _ready$;
195
+ /**
196
+ * @deprecated use hljs.value()
197
+ */
198
+ get ready(): Promise<HLJSApi>;
169
199
  private themeLinkElement?;
170
200
  constructor();
171
201
  /**
@@ -188,6 +218,7 @@ declare class HighlightLoader {
188
218
  static ɵprov: i0.ɵɵInjectableDeclaration<HighlightLoader>;
189
219
  }
190
220
 
221
+ /** @deprecated use standalone imports */
191
222
  declare class HighlightModule {
192
223
  static ɵfac: i0.ɵɵFactoryDeclaration<HighlightModule, never>;
193
224
  static ɵmod: i0.ɵɵNgModuleDeclaration<HighlightModule, never, [typeof HighlightDirective, typeof HighlightAutoDirective], [typeof HighlightDirective, typeof HighlightAutoDirective]>;