All YChart library styles are now scoped under the .ychart-container class to prevent CSS conflicts with host applications. This ensures the library can be safely embedded in any environment without style interference.
When YChartEditor.initView() is called, the library automatically:
- Adds
ychart-containerclass to the target container element - All internal styles are prefixed with
.ychart-containerselector - CSS resets and base styles only apply within the scoped container
- src/styles/ychart-lib-entry.scss – New entry point for library styles
- src/styles/_ychart-lib.scss – All styles wrapped in
.ychart-container { ... } - src/ychartEditor.ts – Automatically applies
ychart-containerclass at line 251
this.viewContainer.classList.add('ychart-container');
<!DOCTYPE html>
<html>
<head>
<!-- Load CSS first to prevent FOUC -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@mieweb/ychart@1.0.7/dist/ychart-editor.css">
</head>
<body>
<!-- Container MUST have defined height -->
<div id="ychart-app" style="width: 100%; height: 600px;"></div>
<script src="https://cdn.jsdelivr.net/npm/@mieweb/ychart@1.0.7/dist/ychart-editor.js"></script>
<script>
const yaml = `
- id: 1
name: CEO
- id: 2
parentId: 1
name: CTO
`;
new YChartEditor().initView('ychart-app', yaml);
</script>
</body>
</html>
The YChart container must have a defined height for proper rendering. Choose one approach:
<div id="ychart-app" style="height: 600px;"></div>
<style>
html, body { height: 100%; margin: 0; }
#ychart-app { height: 100%; }
</style>
<style>
.app-layout { display: flex; flex-direction: column; height: 100vh; }
.header { height: 60px; }
.chart-area { flex: 1; min-height: 0; } /* min-height: 0 is critical! */
</style>
<div class="app-layout">
<header class="header">My Application Header</header>
<div id="ychart-app" class="chart-area"></div>
</div>
import { YChartEditor } from '@mieweb/ychart';
import '@mieweb/ychart/style.css';
const editor = new YChartEditor().initView('container', yamlData);
- ✅ Zero Conflicts – YChart styles won’t interfere with host page CSS
- ✅ Isolation – Host page styles won’t break YChart rendering
- ✅ Framework Compatible – Works alongside Bootstrap, Tailwind, Material UI, etc.
- ✅ Safe Embedding – Can be embedded in legacy applications without refactoring
- ✅ Automatic – No manual configuration needed, scoping happens automatically
All library styles are wrapped in a single parent selector:
// src/styles/_ychart-lib.scss
.ychart-container {
// All YChart styles here
font-family: var(--yc-font-family-base);
position: relative;
width: 100%;
height: 100%;
.ychart-editor-panel { ... }
.ychart-chart-wrapper { ... }
// etc.
}
YChart uses CSS custom properties with --yc- prefix for theming:
--yc-color-primary--yc-color-bg-secondary--yc-font-family-base- etc.
These can be overridden in the host application without breaking isolation.
If upgrading from v1.0.6 or earlier:
- No code changes required
- Scoping is automatic
- Existing integrations continue to work
- Just update the version number in your CDN links or package.json
Verified in production environments:
- ✅ Alongside Bootstrap 5.x
- ✅ Alongside Material-UI
- ✅ Legacy applications with global CSS resets
- ✅ Multiple YChart instances on same page
src/ychartEditor.ts– Main entry point, applies scoping classsrc/styles/ychart-lib-entry.scss– Library style entry pointsrc/styles/_ychart-lib.scss– Scoped library stylesdist/ychart-editor.css– Compiled scoped CSS
- Release: v1.0.7
- NPM:
@mieweb/ychart1.0.7@ - CDN: https://cdn.jsdelivr.net/npm/
mieweb/ychart1.0.7/ - GitHub: https://github.com/mieweb/ychart/releases/tag/v1.0.7