-
Notifications
You must be signed in to change notification settings - Fork 5
feat(compiler): in package source react skin -> html skin (module) #213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
cjpillsbury
wants to merge
3
commits into
main
Choose a base branch
from
feat/compiler-v0
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -30,6 +30,7 @@ export default { | |
| 'skins', | ||
| 'test', | ||
| 'utils', | ||
| 'compiler', | ||
| ]], | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| # @videojs/compiler | ||
|
|
||
| Compiles React skin components to HTML web component modules. | ||
|
|
||
| ## Installation | ||
|
|
||
| ```bash | ||
| pnpm add @videojs/compiler | ||
| ``` | ||
|
|
||
| ## Usage | ||
|
|
||
| ### Basic Compilation | ||
|
|
||
| ```typescript | ||
| import { readFileSync } from 'node:fs'; | ||
| import { compile } from '@videojs/compiler'; | ||
|
|
||
| // Read the React skin source file | ||
| const source = readFileSync('./MediaSkinMinimal.tsx', 'utf-8'); | ||
|
|
||
| // Compile returns a complete HTML module as a string | ||
| const htmlModule = compile({ input: { source } }); | ||
|
|
||
| // Output includes: | ||
| // - Import statements (MediaSkinElement, defineCustomElement, component definitions, styles) | ||
| // - Template function with HTML structure | ||
| // - Class declaration extending MediaSkinElement | ||
| // - Custom element registration | ||
| ``` | ||
|
|
||
| Where `MediaSkinMinimal.tsx` contains: | ||
|
|
||
| ```tsx | ||
| import type { PropsWithChildren } from 'react'; | ||
| import { MediaContainer, PlayButton } from '@videojs/react'; | ||
| import { PlayIcon, PauseIcon } from '@videojs/react/icons'; | ||
| import styles from './styles'; | ||
|
|
||
| export default function MediaSkinMinimal({ children }: PropsWithChildren) { | ||
| return ( | ||
| <MediaContainer className={styles.Container}> | ||
| {children} | ||
| <PlayButton className={`${styles.Button} ${styles.IconButton}`}> | ||
| <PlayIcon className={`${styles.Icon} ${styles.PlayIcon}`} /> | ||
| <PauseIcon className={`${styles.Icon} ${styles.PauseIcon}`} /> | ||
| </PlayButton> | ||
| </MediaContainer> | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
| ### Module Output Structure | ||
|
|
||
| The compiler generates a complete TypeScript/JavaScript module: | ||
|
|
||
| ```typescript | ||
| import { MediaSkinElement } from '@/media/media-skin'; | ||
| import { defineCustomElement } from '@/utils/custom-element'; | ||
| import styles from './styles.css'; | ||
| import '@/define/media-container'; | ||
| import '@/define/media-play-button'; | ||
| import '@/icons'; | ||
|
|
||
| export function getTemplateHTML(): string { | ||
| return /* @__PURE__ */ ` | ||
| ${MediaSkinElement.getTemplateHTML()} | ||
| <style>${styles}</style> | ||
| <media-container class="container"> | ||
| <slot name="media" slot="media"></slot> | ||
| <media-play-button class="button icon-button"> | ||
| <media-play-icon class="icon"></media-play-icon> | ||
| <media-pause-icon class="icon"></media-pause-icon> | ||
| </media-play-button> | ||
| </media-container> | ||
| `; | ||
| } | ||
|
|
||
| export class MediaSkinMinimalElement extends MediaSkinElement { | ||
| static getTemplateHTML: () => string = getTemplateHTML; | ||
| } | ||
|
|
||
| defineCustomElement('media-skin-minimal', MediaSkinMinimalElement); | ||
| ``` | ||
|
|
||
| **Note:** The compiler currently handles JSX/import transformation and generates a placeholder CSS reference (`${styles}`). Compilation of Tailwind utilities to vanilla CSS is not yet implemented. | ||
|
|
||
| ## Documentation | ||
|
|
||
| For detailed information on architecture and design, see [docs/ARCHITECTURE.md](./docs/ARCHITECTURE.md). | ||
|
|
||
| ## Development | ||
|
|
||
| ```bash | ||
| # Run tests | ||
| pnpm test | ||
|
|
||
| # Type check | ||
| pnpm typecheck | ||
|
|
||
| # Build | ||
| pnpm build | ||
| ``` | ||
|
|
||
| ## License | ||
|
|
||
| Apache-2.0 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Low priority thing I'd like to discuss: antfu's linting rules for markdown-owned code blocks is too aggressive for common use cases - it requires syntactically correct code when often what you want is pseudo-code (code with
...and the like), snippets that are technically syntactically invalid (<ReactComponentExample>that isn't e.g. in a return function or assigned to anything), or the like. Whether we convert this to a warning, remove the rule, or try to do something fancier, I think we should fix this so we don't "throw the baby out with the bathwater" on linting markdown.