@mathstack/app-kit 2.1.0 → 2.2.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 (61) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +36 -36
  3. package/{src/lib/baseline-styles → baseline-styles}/_css-reset.scss +118 -118
  4. package/{src/lib/baseline-styles → baseline-styles}/_grid.scss +4 -4
  5. package/{src/lib/baseline-styles → baseline-styles}/_index.scss +6 -6
  6. package/{src/lib/baseline-styles → baseline-styles}/_sass-utils.scss +23 -23
  7. package/{src/lib/baseline-styles → baseline-styles}/_themes.scss +19 -19
  8. package/{src/lib/baseline-styles → baseline-styles}/_typography.scss +232 -232
  9. package/{src/lib/baseline-styles → baseline-styles}/_webkit-scrollbar.scss +22 -22
  10. package/{src/lib/baseline-styles → baseline-styles}/theming/_colors.scss +46 -46
  11. package/{src/lib/baseline-styles → baseline-styles}/theming/_index.scss +2 -2
  12. package/{src/lib/baseline-styles → baseline-styles}/theming/_typography.scss +32 -32
  13. package/fesm2022/mathstack-app-kit.mjs +843 -0
  14. package/fesm2022/mathstack-app-kit.mjs.map +1 -0
  15. package/package.json +14 -7
  16. package/types/mathstack-app-kit.d.ts +394 -0
  17. package/.eslintrc.json +0 -34
  18. package/ng-package.json +0 -15
  19. package/project.json +0 -76
  20. package/src/lib/assets/assets-resource.ts +0 -18
  21. package/src/lib/assets/assets-service.spec.ts +0 -54
  22. package/src/lib/assets/assets-service.ts +0 -73
  23. package/src/lib/assets/index.ts +0 -2
  24. package/src/lib/content-parsing/index.ts +0 -2
  25. package/src/lib/content-parsing/markdown-parser.ts +0 -197
  26. package/src/lib/content-parsing/shiki-highlighter.ts +0 -219
  27. package/src/lib/core/scss/_colors.scss +0 -37
  28. package/src/lib/core/scss/_functions.scss +0 -4
  29. package/src/lib/core/scss/_placeholders.scss +0 -1
  30. package/src/lib/core/scss/_vars.scss +0 -15
  31. package/src/lib/core/testing/stubs/services/assets.resource.stub.ts +0 -3
  32. package/src/lib/core/testing/stubs/services/main.service.stub.ts +0 -5
  33. package/src/lib/core/utilities/deep-merge.spec.ts +0 -29
  34. package/src/lib/core/utilities/deep-merge.ts +0 -21
  35. package/src/lib/core/utilities/index.ts +0 -2
  36. package/src/lib/core/utilities/safe-assign.spec.ts +0 -41
  37. package/src/lib/core/utilities/safe-assign.ts +0 -42
  38. package/src/lib/documentation-display/active-heading-tracker.ts +0 -61
  39. package/src/lib/documentation-display/document-index/document-index.component.html +0 -34
  40. package/src/lib/documentation-display/document-index/document-index.component.scss +0 -56
  41. package/src/lib/documentation-display/document-index/document-index.component.spec.ts +0 -0
  42. package/src/lib/documentation-display/document-index/document-index.component.ts +0 -39
  43. package/src/lib/documentation-display/documentation-config-parser.ts +0 -92
  44. package/src/lib/documentation-display/documentation-content-service.ts +0 -118
  45. package/src/lib/documentation-display/documentation-display.component.html +0 -33
  46. package/src/lib/documentation-display/documentation-display.component.scss +0 -142
  47. package/src/lib/documentation-display/documentation-display.component.spec.ts +0 -0
  48. package/src/lib/documentation-display/documentation-display.component.ts +0 -129
  49. package/src/lib/documentation-display/index.ts +0 -6
  50. package/src/lib/documentation-display/navigation-siblings/navigation-siblings.component.html +0 -31
  51. package/src/lib/documentation-display/navigation-siblings/navigation-siblings.component.scss +0 -68
  52. package/src/lib/documentation-display/navigation-siblings/navigation-siblings.component.spec.ts +0 -0
  53. package/src/lib/documentation-display/navigation-siblings/navigation-siblings.component.ts +0 -52
  54. package/src/lib/ng-utilities/index.ts +0 -2
  55. package/src/lib/ng-utilities/ng-on-changes.spec.ts +0 -117
  56. package/src/lib/ng-utilities/ng-on-changes.ts +0 -50
  57. package/src/lib/ng-utilities/run-ng-change-detection-then.ts +0 -40
  58. package/src/public-api.ts +0 -6
  59. package/tsconfig.lib.json +0 -16
  60. package/tsconfig.lib.prod.json +0 -11
  61. package/tsconfig.spec.json +0 -10
package/project.json DELETED
@@ -1,76 +0,0 @@
1
- {
2
- "name": "app-kit",
3
- "$schema": "../../node_modules/nx/schemas/project-schema.json",
4
- "projectType": "library",
5
- "sourceRoot": "libs/app-kit/src",
6
- "prefix": "adk",
7
- "targets": {
8
- "build": {
9
- "executor": "@angular-devkit/build-angular:ng-packagr",
10
- "options": {
11
- "project": "libs/app-kit/ng-package.json"
12
- },
13
- "configurations": {
14
- "production": {
15
- "tsConfig": "libs/app-kit/tsconfig.lib.prod.json"
16
- },
17
- "development": {
18
- "tsConfig": "libs/app-kit/tsconfig.lib.json"
19
- }
20
- },
21
- "defaultConfiguration": "production",
22
- "outputs": ["{workspaceRoot}/dist/app-kit"]
23
- },
24
- "build-release": {
25
- "executor": "nx:run-commands",
26
- "options": {
27
- "command": "npx nx build app-kit"
28
- }
29
- },
30
- "publish": {
31
- "executor": "nx:run-commands",
32
- "options": {
33
- "command": "cd ./dist/app-kit && npm publish --access public && git push --tags"
34
- }
35
- },
36
- "github-release": {
37
- "executor": "@jscutlery/semver:github",
38
- "options": {
39
- "tag": "{tag}",
40
- "notes": "{notes}"
41
- }
42
- },
43
- "test": {
44
- "executor": "@angular-devkit/build-angular:karma",
45
- "options": {
46
- "tsConfig": "libs/app-kit/tsconfig.spec.json",
47
- "polyfills": ["zone.js", "zone.js/testing"],
48
- "browsers": "ChromeHeadlessNoSandbox",
49
- "watch": false
50
- }
51
- },
52
- "lint": {
53
- "executor": "@angular-eslint/builder:lint",
54
- "options": {
55
- "lintFilePatterns": ["libs/app-kit/**/*.ts", "libs/app-kit/**/*.html"]
56
- },
57
- "outputs": ["{options.outputFile}"]
58
- },
59
- "create-changelog": {
60
- "executor": "nx:run-commands",
61
- "options": {
62
- "command": "touch libs/app-kit/CHANGELOG.md"
63
- }
64
- },
65
- "version": {
66
- "executor": "@jscutlery/semver:version",
67
- "options": {
68
- "preset": "angular",
69
- "skipCommit": true,
70
- "skipRootChangelog": true,
71
- "postTargets": ["build-release", "publish", "github-release"],
72
- "skipCommitTypes": ["build", "ci", "docs", "refactor", "style", "test"]
73
- }
74
- }
75
- }
76
- }
@@ -1,18 +0,0 @@
1
- import { HttpClient } from '@angular/common/http';
2
- import { inject, Injectable } from '@angular/core';
3
- import { Observable } from 'rxjs';
4
- import { AdkAssetResponse } from './assets-service';
5
-
6
- @Injectable({
7
- providedIn: 'root',
8
- })
9
- export class AdkAssetsResource {
10
- private http = inject(HttpClient);
11
-
12
- getAsset(path: string, responseType: AdkAssetResponse): Observable<unknown> {
13
- return this.http.get<unknown>(path, {
14
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
15
- responseType: responseType as any,
16
- });
17
- }
18
- }
@@ -1,54 +0,0 @@
1
- /* eslint-disable @typescript-eslint/no-explicit-any */
2
- import { TestBed } from '@angular/core/testing';
3
- import { of } from 'rxjs';
4
- import { MainServiceStub } from '../core/testing/stubs/services/main.service.stub';
5
- import { AdkAssetsResource } from './assets-resource';
6
- import { AdkAssetResponse, AdkAssetsService } from './assets-service';
7
-
8
- describe('AssetsService', () => {
9
- let service: AdkAssetsService;
10
- let mainServiceStub: MainServiceStub;
11
-
12
- beforeEach(() => {
13
- mainServiceStub = new MainServiceStub();
14
- TestBed.configureTestingModule({
15
- providers: [
16
- AdkAssetsService,
17
- {
18
- provide: AdkAssetsResource,
19
- useValue: mainServiceStub.assetsResourceStub,
20
- },
21
- ],
22
- });
23
- service = TestBed.inject(AdkAssetsService);
24
- });
25
-
26
- describe('setAssetsPath()', () => {
27
- it('should set the assets path', () => {
28
- service.setAssetsPath('test/');
29
- expect(service['assetsPath']).toBe('test/');
30
- });
31
- });
32
-
33
- describe('getAsset()', () => {
34
- beforeEach(() => {
35
- spyOn(service as any, 'fetchAsset').and.returnValue(of('asset text'));
36
- });
37
- it('calls fetch asset if asset does not exist in assets object', (done) => {
38
- service.getAsset('test', AdkAssetResponse.Text).subscribe(() => {
39
- expect(service['fetchAsset']).toHaveBeenCalledOnceWith(
40
- 'test',
41
- AdkAssetResponse.Text
42
- );
43
- done();
44
- });
45
- });
46
- it('does not call fetch asset if asset exists in assets object', (done) => {
47
- service['assets']['test'] = of('asset text');
48
- service.getAsset('test', AdkAssetResponse.Text).subscribe(() => {
49
- expect(service['fetchAsset']).not.toHaveBeenCalled();
50
- done();
51
- });
52
- });
53
- });
54
- });
@@ -1,73 +0,0 @@
1
- import { inject, Injectable } from '@angular/core';
2
- import { csvParse } from 'd3';
3
- import { forkJoin, Observable } from 'rxjs';
4
- import { parse as yamlParse } from 'yaml';
5
- import { AdkAssetsResource } from './assets-resource';
6
-
7
- export enum AdkAssetResponse {
8
- ArrayBuffer = 'arraybuffer',
9
- Blob = 'blob',
10
- Json = 'json',
11
- Text = 'text',
12
- }
13
-
14
- @Injectable({ providedIn: 'root' })
15
- export class AdkAssetsService {
16
- private assets: { [key: string]: Observable<unknown> } = {};
17
- private assetsPath = 'assets/';
18
-
19
- private resource = inject(AdkAssetsResource);
20
-
21
- setAssetsPath(path: string): void {
22
- this.assetsPath = path;
23
- }
24
-
25
- /**
26
- * Loads an asset from the assets folder.
27
- *
28
- * @param assetName The path to the asset from assets/. Should not include leading slash.
29
- * @returns An observable that emits the asset data.
30
- */
31
- getAsset(
32
- assetName: string,
33
- responseType: AdkAssetResponse
34
- ): Observable<unknown> {
35
- if (!this.assets[assetName]) {
36
- this.assets[assetName] = this.fetchAsset(assetName, responseType);
37
- }
38
- return this.assets[assetName];
39
- }
40
-
41
- private fetchAsset(
42
- assetName: string,
43
- responseType: AdkAssetResponse
44
- ): Observable<unknown> {
45
- return this.resource.getAsset(
46
- `${this.assetsPath}${assetName}`,
47
- responseType
48
- );
49
- }
50
-
51
- /**
52
- * Loads multiple assets concurrently.
53
- *
54
- * @param assetNames An array of asset names to load.
55
- * @returns An observable that emits an array of asset data.
56
- */
57
- getAssets(
58
- assetNames: string[],
59
- responseType: AdkAssetResponse
60
- ): Observable<unknown[]> {
61
- return forkJoin(
62
- assetNames.map((assetName) => this.getAsset(assetName, responseType))
63
- );
64
- }
65
-
66
- parseCsv<T>(str: string): T[] {
67
- return csvParse(str) as unknown as T[];
68
- }
69
-
70
- parseYaml<T>(str: string): T {
71
- return yamlParse(str) as T;
72
- }
73
- }
@@ -1,2 +0,0 @@
1
- export * from './assets-resource';
2
- export * from './assets-service';
@@ -1,2 +0,0 @@
1
- export * from './markdown-parser';
2
- export * from './shiki-highlighter';
@@ -1,197 +0,0 @@
1
- import { inject, Injectable } from '@angular/core';
2
- import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
3
- import rehypeAutolinkHeadings from 'rehype-autolink-headings';
4
- import rehypeRaw from 'rehype-raw';
5
- import rehypeSlug from 'rehype-slug';
6
- import rehypeStringify from 'rehype-stringify';
7
- import remarkGfm from 'remark-gfm';
8
- import remarkParse from 'remark-parse';
9
- import remarkRehype from 'remark-rehype';
10
- import { forkJoin, from, map, mergeMap, Observable, of, switchMap } from 'rxjs';
11
- import { BundledLanguage } from 'shiki/langs';
12
- import { BundledTheme } from 'shiki/themes';
13
- import { HighlighterGeneric } from 'shiki/types.mjs';
14
- import { unified } from 'unified';
15
- import { deepMerge } from '../core/utilities/deep-merge';
16
- import { AdkShikiHighlighter, ShikiTheme } from './shiki-highlighter';
17
-
18
- export interface AdkParsedContentSection<Content = string> {
19
- type: string;
20
- content: Content;
21
- html?: SafeHtml;
22
- headers: { id: string; text: string; level: number }[];
23
- }
24
-
25
- export interface AdkMarkdownParsingOptions {
26
- highlighter?: AdkShikiHighlighterOptions;
27
- gfm?: boolean;
28
- headingIds?: boolean;
29
- headingFragmentLinks?: AdkHeadingFragmentLinkOptions;
30
- }
31
-
32
- export interface AdkShikiHighlighterOptions {
33
- highlighter?: HighlighterGeneric<BundledLanguage, BundledTheme>;
34
- theme?: ShikiTheme;
35
- type?: 'html' | 'markdown';
36
- ignoreUnknownLanguage?: boolean;
37
- }
38
-
39
- export interface AdkHeadingFragmentLinkOptions {
40
- createLinks?: boolean;
41
- behavior?: 'append' | 'prepend' | 'wrap' | 'before' | 'after';
42
- }
43
-
44
- const DEFAULT_HIGHLIGHTER_OPTIONS: AdkShikiHighlighterOptions = {
45
- highlighter: undefined,
46
- theme: ShikiTheme.GitHubLight,
47
- type: 'markdown',
48
- ignoreUnknownLanguage: true,
49
- };
50
-
51
- const DEFAULT_PARSING_OPTIONS: AdkMarkdownParsingOptions = {
52
- gfm: true,
53
- headingIds: true,
54
- headingFragmentLinks: { createLinks: false },
55
- highlighter: DEFAULT_HIGHLIGHTER_OPTIONS,
56
- };
57
-
58
- @Injectable()
59
- export class AdkMarkdownParser {
60
- parser: typeof unified;
61
-
62
- private sanitizer = inject(DomSanitizer);
63
- private shikiHighlighter = inject(AdkShikiHighlighter);
64
-
65
- constructor() {
66
- this.parser = unified;
67
- }
68
-
69
- parse(
70
- markdown: string,
71
- options?: AdkMarkdownParsingOptions
72
- ): Observable<AdkParsedContentSection[]> {
73
- const mergedOptions = deepMerge(DEFAULT_PARSING_OPTIONS, options || {});
74
-
75
- return of(mergedOptions).pipe(
76
- mergeMap((_options) => {
77
- if (_options.highlighter && !_options.highlighter.highlighter) {
78
- return from(this.shikiHighlighter.getHighlighter()).pipe(
79
- map((highlighter) => ({
80
- ..._options,
81
- highlighter: {
82
- ..._options.highlighter,
83
- highlighter,
84
- },
85
- }))
86
- );
87
- } else {
88
- return of(_options);
89
- }
90
- }),
91
- switchMap((_options) => {
92
- const sections = this.getSections(markdown);
93
- const parsedSections$ = sections.map((section) => {
94
- return this.parseSection(section, _options);
95
- });
96
- return forkJoin(parsedSections$);
97
- })
98
- );
99
- }
100
-
101
- private getSections(markdown: string): AdkParsedContentSection[] {
102
- const sections: AdkParsedContentSection[] = [];
103
- let currentMarkdown = '';
104
-
105
- const lines = markdown.split('\n');
106
-
107
- for (const line of lines) {
108
- currentMarkdown += line + '\n';
109
- }
110
-
111
- // Add any remaining markdown
112
- if (currentMarkdown.trim()) {
113
- sections.push({
114
- type: 'markdown',
115
- content: currentMarkdown,
116
- html: undefined,
117
- headers: this.getHeaders(currentMarkdown),
118
- });
119
- }
120
-
121
- return sections;
122
- }
123
-
124
- private parseSection(
125
- section: AdkParsedContentSection,
126
- options: AdkMarkdownParsingOptions
127
- ): Observable<AdkParsedContentSection> {
128
- const parsedContent$ = from(
129
- unified()
130
- .use(remarkParse)
131
- .use(options.gfm ? remarkGfm : undefined)
132
- .use(
133
- options.highlighter && options.highlighter.type === 'markdown'
134
- ? this.shikiHighlighter.remarkHighlight
135
- : undefined,
136
- options.highlighter
137
- )
138
- .use(remarkRehype, { allowDangerousHtml: true })
139
- .use(rehypeRaw)
140
- .use(options.headingIds ? rehypeSlug : undefined)
141
- .use(
142
- options.headingFragmentLinks ? rehypeAutolinkHeadings : undefined,
143
- { behavior: options.headingFragmentLinks?.behavior }
144
- )
145
- .use(rehypeStringify)
146
- .process(section.content)
147
- .then((file) => String(file))
148
- );
149
-
150
- return parsedContent$.pipe(
151
- map((parsedContent) => {
152
- const toReturn = {
153
- ...section,
154
- html: this.sanitizer.bypassSecurityTrustHtml(parsedContent),
155
- };
156
- return toReturn;
157
- })
158
- );
159
- }
160
-
161
- getHeaders(markdown: string): { id: string; text: string; level: number }[] {
162
- const headerRegex =
163
- /^(#{1,6})\s*(.+)$|<h([1-6])(?:\s+[^>]*)?>(.*?)<\/h[1-6]>/gm;
164
- const headers: { id: string; text: string; level: number }[] = [];
165
- let match;
166
-
167
- while ((match = headerRegex.exec(markdown)) !== null) {
168
- let level: number;
169
- let text: string;
170
-
171
- if (match[1]) {
172
- // Markdown header, e.g., ## Heading
173
- level = match[1].length;
174
- text = match[2].trim();
175
- } else {
176
- // HTML header, e.g., <h2>Heading</h2>
177
- level = parseInt(match[3], 10);
178
- text = match[4].trim();
179
- }
180
-
181
- const id = text
182
- .toLowerCase()
183
- .replace(/\s+/g, '-')
184
- .replace(/[^\w-]+/g, '');
185
- headers.push({ id, text, level });
186
- }
187
- return headers;
188
- }
189
-
190
- parseComponent(content: string): { name: string; pathTo: string } {
191
- const cleanedLine = content.trim().slice(2, -2).trim();
192
- const [nameKV, pathToKV] = cleanedLine.split(',');
193
- const name = nameKV.split(':')[1]?.trim();
194
- const pathTo = pathToKV.split(':')[1]?.trim();
195
- return { name, pathTo };
196
- }
197
- }
@@ -1,219 +0,0 @@
1
- import { Injectable } from '@angular/core';
2
- import { Root } from 'hast';
3
- import { fromParse5 } from 'hast-util-from-parse5';
4
- import { parse } from 'parse5';
5
- import { createHighlighter } from 'shiki/index.mjs';
6
- import { BundledLanguage } from 'shiki/langs';
7
- import { BundledTheme } from 'shiki/themes';
8
- import { HighlighterGeneric } from 'shiki/types.mjs';
9
- import { visit } from 'unist-util-visit';
10
- import { AdkShikiHighlighterOptions } from './markdown-parser';
11
-
12
- export const defaultHighlighterLangs = [
13
- 'json',
14
- 'ts',
15
- 'js',
16
- 'html',
17
- 'css',
18
- 'scss',
19
- 'yaml',
20
- 'angular-html',
21
- 'angular-ts',
22
- 'mermaid',
23
- 'bash',
24
- ];
25
-
26
- export enum ShikiTheme {
27
- Andromeeda = 'andromeeda',
28
- AuroraX = 'aurora-x',
29
- AyuDark = 'ayu-dark',
30
- CatppuccinFrappe = 'catppuccin-frappe',
31
- CatppuccinLatte = 'catppuccin-latte',
32
- CatppuccinMacchiato = 'catppuccin-macchiato',
33
- CatppuccinMocha = 'catppuccin-mocha',
34
- DarkPlus = 'dark-plus',
35
- DraculaTheme = 'dracula',
36
- DraculaThemeSoft = 'dracula-soft',
37
- EverforestDark = 'everforest-dark',
38
- EverforestLight = 'everforest-light',
39
- GitHubDark = 'github-dark',
40
- GitHubDarkDefault = 'github-dark-default',
41
- GitHubDarkDimmed = 'github-dark-dimmed',
42
- GitHubDarkHighContrast = 'github-dark-high-contrast',
43
- GitHubLight = 'github-light',
44
- GitHubLightDefault = 'github-light-default',
45
- GitHubLightHighContrast = 'github-light-high-contrast',
46
- Houston = 'houston',
47
- LaserWave = 'laserwave',
48
- LightPlus = 'light-plus',
49
- MaterialTheme = 'material-theme',
50
- MaterialThemeDarker = 'material-theme-darker',
51
- MaterialThemeLighter = 'material-theme-lighter',
52
- MaterialThemeOcean = 'material-theme-ocean',
53
- MaterialThemePalenight = 'material-theme-palenight',
54
- MinDark = 'min-dark',
55
- MinLight = 'min-light',
56
- Monokai = 'monokai',
57
- NightOwl = 'night-owl',
58
- Nord = 'nord',
59
- OneDarkPro = 'one-dark-pro',
60
- OneLight = 'one-light',
61
- Plastic = 'plastic',
62
- Poimandres = 'poimandres',
63
- Red = 'red',
64
- RosePine = 'rose-pine',
65
- RosePineDawn = 'rose-pine-dawn',
66
- RosePineMoon = 'rose-pine-moon',
67
- SlackDark = 'slack-dark',
68
- SlackOchin = 'slack-ochin',
69
- SnazzyLight = 'snazzy-light',
70
- SolarizedDark = 'solarized-dark',
71
- SolarizedLight = 'solarized-light',
72
- Synthwave84 = 'synthwave-84',
73
- TokyoNight = 'tokyo-night',
74
- Vesper = 'vesper',
75
- VitesseBlack = 'vitesse-black',
76
- VitesseDark = 'vitesse-dark',
77
- VitesseLight = 'vitesse-light',
78
- }
79
-
80
- const MISSING_HIGHLIGHTER = `Please provide a \`shiki\` highlighter instance via \`options\`.`;
81
-
82
- @Injectable({
83
- providedIn: 'root',
84
- })
85
- export class AdkShikiHighlighter {
86
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
87
- private highlighterPromise: Promise<
88
- HighlighterGeneric<BundledLanguage, BundledTheme>
89
- > | null = null;
90
-
91
- /**
92
- * Initialize the highlighter. This should only be called one in an application.
93
- *
94
- * @param themes an array of any Shiki themes you may want to use anywhere in the app. You can control which theme for your particular parsing by passing the theme name to the actual parsing function.
95
- *
96
- * @returns void
97
- */
98
- async initialize(
99
- themes: ShikiTheme[],
100
- langs: string[] = defaultHighlighterLangs
101
- ): Promise<void> {
102
- if (!this.highlighterPromise) {
103
- this.highlighterPromise = createHighlighter({
104
- langs,
105
- themes: themes.length ? themes : [ShikiTheme.GitHubLight],
106
- });
107
- }
108
- await this.highlighterPromise;
109
- }
110
-
111
- async getHighlighter(): Promise<
112
- HighlighterGeneric<BundledLanguage, BundledTheme>
113
- > {
114
- if (!this.highlighterPromise) {
115
- throw new Error(
116
- 'Highlighter is not initialized. Please call initialize() once in your application first.'
117
- );
118
- }
119
- return this.highlighterPromise;
120
- }
121
-
122
- remarkHighlight(options: AdkShikiHighlighterOptions): (tree: Root) => void {
123
- const highlighter = options.highlighter;
124
- if (!options.highlighter) {
125
- throw new Error(MISSING_HIGHLIGHTER);
126
- }
127
- const loadedLanguages = highlighter.getLoadedLanguages();
128
- const ignoreUnknownLanguage =
129
- options.ignoreUnknownLanguage === undefined
130
- ? true
131
- : options.ignoreUnknownLanguage;
132
-
133
- const visitor = (node) => {
134
- if (!loadedLanguages.includes(node.lang)) {
135
- if (ignoreUnknownLanguage) {
136
- node.lang = null;
137
- } else {
138
- return;
139
- }
140
- }
141
-
142
- const highlighted = highlighter.codeToHtml(node.value, {
143
- lang: node.lang,
144
- theme: options.theme,
145
- });
146
-
147
- node.type = 'html';
148
- node.value = highlighted;
149
- };
150
-
151
- const transformer = (tree: Root) => {
152
- visit(tree, 'code', visitor);
153
- };
154
-
155
- return transformer;
156
- }
157
-
158
- rehypeHighlight(options: AdkShikiHighlighterOptions): (tree: Root) => void {
159
- const highlighter = options.highlighter;
160
- if (!options.highlighter) {
161
- throw new Error(MISSING_HIGHLIGHTER);
162
- }
163
-
164
- const visitor = (node, _index, parent) => {
165
- if (!parent || parent.tagName !== 'pre' || node.tagName !== 'code') {
166
- return;
167
- }
168
-
169
- const [langClass] = node.properties.className;
170
- const lang = langClass.replace('language-', '');
171
-
172
- if (highlighter.getLoadedLanguages().includes(lang)) {
173
- const code = node.children[0]?.value;
174
- if (!code) {
175
- return;
176
- }
177
- const highlighted = highlighter.codeToHtml(code, {
178
- lang,
179
- theme: options.theme,
180
- });
181
- const parsed = parse(highlighted);
182
- const hastTree = fromParse5(parsed);
183
-
184
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
185
- const content = (hastTree as any).children[0].children[1].children[0]
186
- .children[0];
187
-
188
- content.properties.class = ['shiki', 'shiki-' + lang, langClass];
189
-
190
- node.properties = content.properties;
191
- node.children = content.children;
192
- }
193
- };
194
-
195
- const transformer = (tree: Root) => {
196
- visit(tree, 'element', visitor);
197
- };
198
-
199
- return transformer;
200
- }
201
-
202
- getLanguage(node): string {
203
- const dataLanguage = node.properties.dataLanguage;
204
-
205
- if (dataLanguage != null) {
206
- return dataLanguage;
207
- }
208
-
209
- const className = node.properties.className || [];
210
-
211
- for (const classListItem of className) {
212
- if (classListItem.slice(0, 9) === 'language-') {
213
- return classListItem.slice(9).toLowerCase();
214
- }
215
- }
216
-
217
- return null;
218
- }
219
- }
@@ -1,37 +0,0 @@
1
- $primary-0: var(--hsi-adk-color-primary-0);
2
- $primary-5: var(--hsi-adk-color-primary-5);
3
- $primary-10: var(--hsi-adk-color-primary-10);
4
- $primary-15: var(--hsi-adk-color-primary-15);
5
- $primary-20: var(--hsi-adk-color-primary-20);
6
- $primary-25: var(--hsi-adk-color-primary-25);
7
- $primary-30: var(--hsi-adk-color-primary-30);
8
- $primary-35: var(--hsi-adk-color-primary-35);
9
- $primary-40: var(--hsi-adk-color-primary-40);
10
- $primary-50: var(--hsi-adk-color-primary-50);
11
- $primary-60: var(--hsi-adk-color-primary-60);
12
- $primary-70: var(--hsi-adk-color-primary-70);
13
- $primary-80: var(--hsi-adk-color-primary-80);
14
- $primary-90: var(--hsi-adk-color-primary-90);
15
- $primary-95: var(--hsi-adk-color-primary-95);
16
- $primary-98: var(--hsi-adk-color-primary-98);
17
- $primary-99: var(--hsi-adk-color-primary-99);
18
- $primary-100: var(--hsi-adk-color-primary-100);
19
-
20
- $muted-primary-0: var(--hsi-adk-color-muted-primary-0);
21
- $muted-primary-5: var(--hsi-adk-color-muted-primary-5);
22
- $muted-primary-10: var(--hsi-adk-color-muted-primary-10);
23
- $muted-primary-15: var(--hsi-adk-color-muted-primary-15);
24
- $muted-primary-20: var(--hsi-adk-color-muted-primary-20);
25
- $muted-primary-25: var(--hsi-adk-color-muted-primary-25);
26
- $muted-primary-30: var(--hsi-adk-color-muted-primary-30);
27
- $muted-primary-35: var(--hsi-adk-color-muted-primary-35);
28
- $muted-primary-40: var(--hsi-adk-color-muted-primary-40);
29
- $muted-primary-50: var(--hsi-adk-color-muted-primary-50);
30
- $muted-primary-60: var(--hsi-adk-color-muted-primary-60);
31
- $muted-primary-70: var(--hsi-adk-color-muted-primary-70);
32
- $muted-primary-80: var(--hsi-adk-color-muted-primary-80);
33
- $muted-primary-90: var(--hsi-adk-color-muted-primary-90);
34
- $muted-primary-95: var(--hsi-adk-color-muted-primary-95);
35
- $muted-primary-98: var(--hsi-adk-color-muted-primary-98);
36
- $muted-primary-99: var(--hsi-adk-color-muted-primary-99);
37
- $muted-primary-100: var(--hsi-adk-color-muted-primary-100);
@@ -1,4 +0,0 @@
1
- @function grid($number) {
2
- $grid: 0.25rem;
3
- @return $number * $grid;
4
- }
@@ -1 +0,0 @@
1
- @forward '../../baseline-styles/typography';