LayMeshDocs
中文

Local third-party CSS and shared themes#

Style and animation libraries

Keep third-party CSS unchanged#

Third-party libraries normally use .css; import them without renaming. Download them into the project and retain licenses and relative dependencies. Current compilation does not download URL/CDN imports. This example vendors original Milligram 1.4.1 CSS under MIT. Its manifest records the pinned source and SHA-256. It is a project dependency, not another bundled library.

Complete project layout#

text
third-party/  direct.lay  main.lay  theme.css  palette.css  assets/pattern.svg  vendor/milligram.css  vendor/LICENSE.txt  vendor/manifest.json

The source project exposes individual source/resource tabs. Keep images, themes and dependencies together.

Method 1: stylesheet arguments#

Full source
direct.lay
page=canvas(size=(140mm,80mm),stylesheet=["vendor/milligram.css","palette.css"],background="#f6f7fb")items=[]for appearance,label in [("button","Milligram filled"),("button button-outline","Milligram outlined")] { target=page.top_left gap=(15mm,20mm) if len(items)>0 {target=items[len(items)-1].top_right gap=(25mm,0mm)} item=page.add(rect(size=(40mm,25mm),class=appearance),target=target,offset=gap) items=append(items,item) page.add(text(label,class="caption"),target=item.bottom_left,offset=(0mm,8mm))}

Preview

Background
Preparing preview…
Direct
Preparing preview…
Total —
Details

Not run yet

Measured in this browser; excludes debounce.

Edits stay on this page
Dependencies
  • examples/libraries/third-party/direct.lay
  • examples/libraries/third-party/palette.css
  • examples/libraries/third-party/vendor/milligram.css

Use stylesheet="vendor/milligram.css" for one file, or an ordered list for several. The project palette follows the library. The button class supplies supported appearance declarations.

Method 2: string and url imports#

Full source
main.lay
page=canvas(size=(140mm,80mm),stylesheet="theme.css",background="#f6f7fb")button=page.add(rect(size=(40mm,25mm),class="button"),target=page.top_left,offset=(15mm,20mm))pattern=page.add(rect(size=(40mm,25mm),class="tile"),target=button.top_right,offset=(25mm,0mm))for item,label in [(button,"Milligram appearance"),(pattern,"Relative SVG resource")] { page.add(text(label,class="caption"),target=item.bottom_left,offset=(0mm,8mm))}

Preview

Background
Preparing preview…
Main
Preparing preview…
Total —
Details

Not run yet

Measured in this browser; excludes debounce.

Edits stay on this page
Dependencies
  • examples/libraries/third-party/assets/pattern.svg
  • examples/libraries/third-party/main.lay
  • examples/libraries/third-party/palette.css
  • examples/libraries/third-party/theme.css
  • examples/libraries/third-party/vendor/milligram.css

theme.css uses @import "vendor/milligram.css"; and @import url("palette.css");. Inline Lay style blocks accept the same forms. Import paths resolve from the importing file; background SVG paths resolve from the declaring stylesheet, rather than the terminal working directory.

Then share a theme between pages#

Full source
shared.laydoc
report=document(name="Shared library theme")report.add(page(src="shared-page-1.lay",name="First"))report.add(page(src="shared-page-2.lay",name="Second"))

Preview

Background
Preparing animation…
Shared
Preparing preview…
Total —
Details

Not run yet

Measured in this browser; excludes debounce.

Edits stay on this page
Dependencies
  • examples/libraries/shared-page-1.lay
  • examples/libraries/shared-page-2.lay
  • examples/libraries/shared-theme.lcss
  • examples/libraries/shared.laydoc

Both pages import shared-theme.lcss. An authored theme can also use .css; .lcss identifies LayMesh styling and extensions to the editor. Extract a separate theme when multiple files reuse it.

Compatibility, overrides and editor support#

Loading a full stylesheet does not implement every web feature. Supported colors, fonts, borders, corners and shadows remain effective; unsupported selectors, properties and rules produce W_CSS summaries. See compatibility. Missing files and cycles remain errors.

Later declarations win at equal importance/specificity; explicit Lay parameters always win. See shadow overrides.

External .css keeps VS Code native CSS editing. LayMesh indexes it as a dependency, supplying imported classes, variables and keyframes to completion, hover and navigation in .lay/.lcss. Unsaved changes refresh the index. Web editing and Python queries share that service.