@semantic-components/code 0.63.0 → 0.64.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/esm2022/index.js +2 -0
  2. package/esm2022/index.js.map +1 -0
  3. package/esm2022/lib/components/code-editor/code-editor-content.js +435 -0
  4. package/esm2022/lib/components/code-editor/code-editor-content.js.map +1 -0
  5. package/esm2022/lib/components/code-editor/code-editor-copy-button.js +90 -0
  6. package/esm2022/lib/components/code-editor/code-editor-copy-button.js.map +1 -0
  7. package/esm2022/lib/components/code-editor/code-editor-footer.js +27 -0
  8. package/esm2022/lib/components/code-editor/code-editor-footer.js.map +1 -0
  9. package/esm2022/lib/components/code-editor/code-editor-header.js +27 -0
  10. package/esm2022/lib/components/code-editor/code-editor-header.js.map +1 -0
  11. package/esm2022/lib/components/code-editor/code-editor-label.js +27 -0
  12. package/esm2022/lib/components/code-editor/code-editor-label.js.map +1 -0
  13. package/esm2022/lib/components/code-editor/code-editor.js +27 -0
  14. package/esm2022/lib/components/code-editor/code-editor.js.map +1 -0
  15. package/esm2022/lib/components/code-editor/index.js +7 -0
  16. package/esm2022/lib/components/code-editor/index.js.map +1 -0
  17. package/esm2022/lib/components/code-viewer/code-viewer-content.js +70 -0
  18. package/esm2022/lib/components/code-viewer/code-viewer-content.js.map +1 -0
  19. package/esm2022/lib/components/code-viewer/code-viewer-header.js +27 -0
  20. package/esm2022/lib/components/code-viewer/code-viewer-header.js.map +1 -0
  21. package/esm2022/lib/components/code-viewer/code-viewer-label.js +27 -0
  22. package/esm2022/lib/components/code-viewer/code-viewer-label.js.map +1 -0
  23. package/esm2022/lib/components/code-viewer/code-viewer.js +27 -0
  24. package/esm2022/lib/components/code-viewer/code-viewer.js.map +1 -0
  25. package/esm2022/lib/components/code-viewer/index.js +5 -0
  26. package/esm2022/lib/components/code-viewer/index.js.map +1 -0
  27. package/esm2022/lib/components/index.js +3 -0
  28. package/esm2022/lib/components/index.js.map +1 -0
  29. package/esm2022/semantic-components-code.js +5 -0
  30. package/esm2022/semantic-components-code.js.map +1 -0
  31. package/lib/components/code-editor/code-editor-content.d.ts +57 -0
  32. package/lib/components/code-editor/code-editor-copy-button.d.ts +11 -0
  33. package/lib/components/code-editor/code-editor-footer.d.ts +7 -0
  34. package/lib/components/code-editor/code-editor-header.d.ts +7 -0
  35. package/lib/components/code-editor/code-editor-label.d.ts +7 -0
  36. package/lib/components/code-editor/code-editor.d.ts +7 -0
  37. package/lib/components/code-viewer/code-viewer-content.d.ts +17 -0
  38. package/lib/components/code-viewer/code-viewer-header.d.ts +7 -0
  39. package/lib/components/code-viewer/code-viewer-label.d.ts +7 -0
  40. package/lib/components/code-viewer/code-viewer.d.ts +7 -0
  41. package/package.json +15 -3
  42. package/semantic-components-code.d.ts +5 -0
  43. package/eslint.config.mjs +0 -48
  44. package/ng-package.json +0 -8
  45. package/project.json +0 -28
  46. package/src/lib/components/code-editor/README.md +0 -368
  47. package/src/lib/components/code-editor/code-editor-content.ts +0 -507
  48. package/src/lib/components/code-editor/code-editor-copy-button.ts +0 -77
  49. package/src/lib/components/code-editor/code-editor-footer.ts +0 -31
  50. package/src/lib/components/code-editor/code-editor-header.ts +0 -31
  51. package/src/lib/components/code-editor/code-editor-label.ts +0 -28
  52. package/src/lib/components/code-editor/code-editor.ts +0 -31
  53. package/src/lib/components/code-viewer/README.md +0 -178
  54. package/src/lib/components/code-viewer/code-viewer-content.ts +0 -96
  55. package/src/lib/components/code-viewer/code-viewer-header.ts +0 -31
  56. package/src/lib/components/code-viewer/code-viewer-label.ts +0 -28
  57. package/src/lib/components/code-viewer/code-viewer.ts +0 -28
  58. package/tsconfig.json +0 -28
  59. package/tsconfig.lib.json +0 -12
  60. package/tsconfig.lib.prod.json +0 -7
  61. /package/{src/index.ts → index.d.ts} +0 -0
  62. /package/{src/lib/components/code-editor/index.ts → lib/components/code-editor/index.d.ts} +0 -0
  63. /package/{src/lib/components/code-viewer/index.ts → lib/components/code-viewer/index.d.ts} +0 -0
  64. /package/{src/lib/components/index.ts → lib/components/index.d.ts} +0 -0
@@ -1,178 +0,0 @@
1
- # Code Viewer Components
2
-
3
- A read-only code display component with syntax highlighting powered by [Shiki](https://shiki.style/) and shadcn/ui styling. Automatically follows the app's light/dark theme.
4
-
5
- ## Import
6
-
7
- ```typescript
8
- import { ScCodeViewer, ScCodeViewerHeader, ScCodeViewerLabel, ScCodeViewerContent, ScCodeViewerLanguage } from '@semantic-components/ui-lab';
9
- ```
10
-
11
- ## Architecture
12
-
13
- The component uses Shiki's dual-theme feature (`github-light` + `github-dark`) with `defaultColor: false` to generate CSS variable-based output. The CSS switches between `--shiki-light` and `--shiki-dark` variables based on the `.dark` class on the document root.
14
-
15
- ```
16
- ScCodeViewer (Root - div[sc-code-viewer])
17
- ├── ScCodeViewerHeader (Header - div[sc-code-viewer-header])
18
- │ ├── ScCodeViewerLabel (Label - span[sc-code-viewer-label])
19
- │ └── ScCopyButton (Copy button)
20
- └── ScCodeViewerContent (Content - div[sc-code-viewer-content])
21
- ```
22
-
23
- ## Components
24
-
25
- | Component | Selector | Description |
26
- | --------------------- | ----------------------------- | -------------------------------- |
27
- | `ScCodeViewer` | `div[sc-code-viewer]` | Root container with border |
28
- | `ScCodeViewerHeader` | `div[sc-code-viewer-header]` | Header bar with border |
29
- | `ScCodeViewerLabel` | `span[sc-code-viewer-label]` | Label for filename or language |
30
- | `ScCodeViewerContent` | `div[sc-code-viewer-content]` | Content with syntax highlighting |
31
-
32
- ## Inputs
33
-
34
- ### ScCodeViewer (Root)
35
-
36
- | Input | Type | Default | Description |
37
- | ------- | -------- | ------- | ---------------------- |
38
- | `class` | `string` | `''` | Additional CSS classes |
39
-
40
- The root container with border and rounded corners.
41
-
42
- ### ScCodeViewerHeader
43
-
44
- | Input | Type | Default | Description |
45
- | ------- | -------- | ------- | ---------------------- |
46
- | `class` | `string` | `''` | Additional CSS classes |
47
-
48
- Header bar with bottom border for filename/language label and copy button.
49
-
50
- ### ScCodeViewerLabel
51
-
52
- | Input | Type | Default | Description |
53
- | ------- | -------- | ------- | ---------------------- |
54
- | `class` | `string` | `''` | Additional CSS classes |
55
-
56
- Label for displaying filename or language with muted foreground styling.
57
-
58
- ### ScCodeViewerContent
59
-
60
- | Input | Type | Default | Description |
61
- | ----------------- | ---------------------- | ------------- | -------------------------------- |
62
- | `code` | `string` | **required** | The source code to display |
63
- | `language` | `ScCodeViewerLanguage` | `'plaintext'` | Language for syntax highlighting |
64
- | `showLineNumbers` | `boolean` | `false` | Whether to show line numbers |
65
- | `class` | `string` | `''` | Additional CSS classes |
66
-
67
- The content component with Shiki syntax highlighting.
68
-
69
- ## Supported Languages
70
-
71
- `angular-ts` | `typescript` | `javascript` | `html` | `css` | `json` | `python` | `bash` | `shell` | `markdown` | `yaml` | `sql` | `go` | `rust` | `java` | `plaintext`
72
-
73
- ## Usage
74
-
75
- ### Basic Usage
76
-
77
- ```html
78
- <div sc-code-viewer>
79
- <div sc-code-viewer-header>
80
- <span sc-code-viewer-label>TypeScript</span>
81
- <button sc-copy-button [value]="code"></button>
82
- </div>
83
- <div sc-code-viewer-content [code]="code" language="typescript"></div>
84
- </div>
85
- ```
86
-
87
- ### With Filename
88
-
89
- ```html
90
- <div sc-code-viewer>
91
- <div sc-code-viewer-header>
92
- <span sc-code-viewer-label>app.component.ts</span>
93
- <button sc-copy-button [value]="code"></button>
94
- </div>
95
- <div sc-code-viewer-content [code]="code" language="angular-ts"></div>
96
- </div>
97
- ```
98
-
99
- ### With Line Numbers
100
-
101
- ```html
102
- <div sc-code-viewer>
103
- <div sc-code-viewer-header>
104
- <span sc-code-viewer-label>{{ filename }}</span>
105
- <button sc-copy-button [value]="code"></button>
106
- </div>
107
- <div sc-code-viewer-content [code]="code" language="typescript" [showLineNumbers]="true"></div>
108
- </div>
109
- ```
110
-
111
- ### Without Header
112
-
113
- ```html
114
- <div sc-code-viewer>
115
- <div sc-code-viewer-content [code]="code" language="json"></div>
116
- </div>
117
- ```
118
-
119
- ### With Max Height
120
-
121
- ```html
122
- <div sc-code-viewer>
123
- <div sc-code-viewer-header>
124
- <span sc-code-viewer-label>{{ language }}</span>
125
- <button sc-copy-button [value]="code"></button>
126
- </div>
127
- <div sc-code-viewer-content [code]="longCode" language="typescript" maxHeight="300px"></div>
128
- </div>
129
- ```
130
-
131
- ### Custom Header Content
132
-
133
- ```html
134
- <div sc-code-viewer>
135
- <div sc-code-viewer-header>
136
- <div class="flex items-center gap-2">
137
- <svg class="size-4"><!-- icon --></svg>
138
- <span sc-code-viewer-label>{{ filename }}</span>
139
- <span class="text-xs text-muted-foreground">({{ lines }} lines)</span>
140
- </div>
141
- <div class="flex gap-2">
142
- <button>Download</button>
143
- <button sc-copy-button [value]="code"></button>
144
- </div>
145
- </div>
146
- <div sc-code-viewer-content [code]="code" [language]="language"></div>
147
- </div>
148
- ```
149
-
150
- ## Theming
151
-
152
- The component automatically follows the app's theme:
153
-
154
- - **Light mode**: Uses `github-light` Shiki theme
155
- - **Dark mode**: Uses `github-dark` Shiki theme (activated by `.dark` class on `<html>`)
156
-
157
- No manual theme configuration is needed. The component renders both theme colors as CSS variables and switches between them with CSS.
158
-
159
- ## Features
160
-
161
- - **Composable Architecture**: Build custom layouts with separate header and content components
162
- - **Syntax Highlighting**: Powered by Shiki with 30+ languages supported
163
- - **Automatic Theming**: Follows app's light/dark mode automatically
164
- - **Line Numbers**: Optional line number display
165
- - **Copy Button**: Built-in copy-to-clipboard functionality with ScCopyButton
166
- - **Customizable**: All components accept custom classes
167
- - **Accessible**: Proper semantic HTML and ARIA attributes
168
-
169
- ## Styling
170
-
171
- The components use Tailwind CSS with shadcn/ui design tokens:
172
-
173
- - **Container** (`ScCodeViewer`): `rounded-lg border border-border overflow-hidden`
174
- - **Header** (`ScCodeViewerHeader`): `flex items-center justify-between border-b border-border px-4 py-2`
175
- - **Label** (`ScCodeViewerLabel`): `text-xs font-medium text-muted-foreground`
176
- - **Content** (`ScCodeViewerContent`): `overflow-auto` with configurable max-height
177
- - **Code font**: System monospace stack (`ui-monospace, SFMono-Regular, ...`)
178
- - **Line numbers**: Muted foreground at 50% opacity, non-selectable
@@ -1,96 +0,0 @@
1
- import {
2
- ChangeDetectionStrategy,
3
- Component,
4
- computed,
5
- effect,
6
- inject,
7
- input,
8
- signal,
9
- ViewEncapsulation,
10
- } from '@angular/core';
11
- import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
12
- import { codeToHtml } from 'shiki';
13
- import { cn } from '@semantic-components/ui';
14
-
15
- export type ScCodeViewerLanguage =
16
- | 'angular-ts'
17
- | 'typescript'
18
- | 'javascript'
19
- | 'html'
20
- | 'css'
21
- | 'json'
22
- | 'python'
23
- | 'bash'
24
- | 'shell'
25
- | 'markdown'
26
- | 'yaml'
27
- | 'sql'
28
- | 'go'
29
- | 'rust'
30
- | 'java'
31
- | 'plaintext';
32
-
33
- @Component({
34
- selector: 'div[sc-code-viewer-content]',
35
- template: `
36
- @if (highlightedHtml()) {
37
- <div [class]="contentClass()" [innerHTML]="highlightedHtml()"></div>
38
- } @else {
39
- <pre
40
- class="m-0 p-4 text-sm leading-relaxed font-mono text-foreground"
41
- ><code>{{ code() }}</code></pre>
42
- }
43
- `,
44
- host: {
45
- 'data-slot': 'code-viewer-content',
46
- '[class]': 'wrapperClass()',
47
- },
48
- encapsulation: ViewEncapsulation.None,
49
- changeDetection: ChangeDetectionStrategy.OnPush,
50
- })
51
- export class ScCodeViewerContent {
52
- readonly code = input.required<string>();
53
- readonly language = input<ScCodeViewerLanguage>('plaintext');
54
- readonly showLineNumbers = input(false);
55
- readonly classInput = input<string>('', { alias: 'class' });
56
-
57
- private readonly sanitizer = inject(DomSanitizer);
58
-
59
- protected readonly highlightedHtml = signal<SafeHtml | null>(null);
60
-
61
- protected readonly wrapperClass = computed(() =>
62
- cn('overflow-auto', this.classInput()),
63
- );
64
-
65
- protected readonly contentClass = computed(() =>
66
- cn(this.showLineNumbers() && 'shiki-line-numbers'),
67
- );
68
-
69
- constructor() {
70
- effect(() => {
71
- const code = this.code();
72
- const lang = this.language();
73
-
74
- this.highlight(code, lang);
75
- });
76
- }
77
-
78
- private async highlight(
79
- code: string,
80
- lang: ScCodeViewerLanguage,
81
- ): Promise<void> {
82
- try {
83
- const html = await codeToHtml(code, {
84
- lang,
85
- themes: {
86
- light: 'github-light',
87
- dark: 'github-dark',
88
- },
89
- defaultColor: false,
90
- });
91
- this.highlightedHtml.set(this.sanitizer.bypassSecurityTrustHtml(html));
92
- } catch {
93
- this.highlightedHtml.set(null);
94
- }
95
- }
96
- }
@@ -1,31 +0,0 @@
1
- import {
2
- ChangeDetectionStrategy,
3
- Component,
4
- computed,
5
- input,
6
- ViewEncapsulation,
7
- } from '@angular/core';
8
- import { cn } from '@semantic-components/ui';
9
-
10
- @Component({
11
- selector: 'div[sc-code-viewer-header]',
12
- template: `
13
- <ng-content />
14
- `,
15
- host: {
16
- 'data-slot': 'code-viewer-header',
17
- '[class]': 'class()',
18
- },
19
- encapsulation: ViewEncapsulation.None,
20
- changeDetection: ChangeDetectionStrategy.OnPush,
21
- })
22
- export class ScCodeViewerHeader {
23
- readonly classInput = input<string>('', { alias: 'class' });
24
-
25
- protected readonly class = computed(() =>
26
- cn(
27
- 'flex items-center justify-between border-b border-border px-4 py-2',
28
- this.classInput(),
29
- ),
30
- );
31
- }
@@ -1,28 +0,0 @@
1
- import {
2
- ChangeDetectionStrategy,
3
- Component,
4
- computed,
5
- input,
6
- ViewEncapsulation,
7
- } from '@angular/core';
8
- import { cn } from '@semantic-components/ui';
9
-
10
- @Component({
11
- selector: 'span[sc-code-viewer-label]',
12
- template: `
13
- <ng-content />
14
- `,
15
- host: {
16
- 'data-slot': 'code-viewer-label',
17
- '[class]': 'class()',
18
- },
19
- encapsulation: ViewEncapsulation.None,
20
- changeDetection: ChangeDetectionStrategy.OnPush,
21
- })
22
- export class ScCodeViewerLabel {
23
- readonly classInput = input<string>('', { alias: 'class' });
24
-
25
- protected readonly class = computed(() =>
26
- cn('text-xs font-medium text-muted-foreground', this.classInput()),
27
- );
28
- }
@@ -1,28 +0,0 @@
1
- import {
2
- ChangeDetectionStrategy,
3
- Component,
4
- computed,
5
- input,
6
- ViewEncapsulation,
7
- } from '@angular/core';
8
- import { cn } from '@semantic-components/ui';
9
-
10
- @Component({
11
- selector: 'div[sc-code-viewer]',
12
- template: `
13
- <ng-content />
14
- `,
15
- host: {
16
- 'data-slot': 'code-viewer',
17
- '[class]': 'class()',
18
- },
19
- encapsulation: ViewEncapsulation.None,
20
- changeDetection: ChangeDetectionStrategy.OnPush,
21
- })
22
- export class ScCodeViewer {
23
- readonly classInput = input<string>('', { alias: 'class' });
24
-
25
- protected readonly class = computed(() =>
26
- cn('overflow-hidden rounded-lg border border-border', this.classInput()),
27
- );
28
- }
package/tsconfig.json DELETED
@@ -1,28 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.base.json",
3
- "compilerOptions": {
4
- "isolatedModules": true,
5
- "target": "es2022",
6
- "moduleResolution": "bundler",
7
- "strict": true,
8
- "noImplicitOverride": true,
9
- "noPropertyAccessFromIndexSignature": true,
10
- "noImplicitReturns": true,
11
- "noFallthroughCasesInSwitch": true,
12
- "emitDecoratorMetadata": false,
13
- "module": "preserve"
14
- },
15
- "angularCompilerOptions": {
16
- "enableI18nLegacyMessageIdFormat": false,
17
- "strictInjectionParameters": true,
18
- "strictInputAccessModifiers": true,
19
- "strictTemplates": true
20
- },
21
- "files": [],
22
- "include": [],
23
- "references": [
24
- {
25
- "path": "./tsconfig.lib.json"
26
- }
27
- ]
28
- }
package/tsconfig.lib.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "../../dist/out-tsc",
5
- "declaration": true,
6
- "declarationMap": true,
7
- "inlineSources": true,
8
- "types": []
9
- },
10
- "include": ["src/**/*.ts"],
11
- "exclude": ["src/**/*.spec.ts", "src/**/*.test.ts"]
12
- }
@@ -1,7 +0,0 @@
1
- {
2
- "extends": "./tsconfig.lib.json",
3
- "compilerOptions": {
4
- "declarationMap": false
5
- },
6
- "angularCompilerOptions": {}
7
- }
File without changes