HTML and DOM
Mount the adapter on an element to measure its font and container width. Call destroy when removing the element; update to change options.
Static HTML without a bundler
Serve an ESM distribution through a pinned version URL, import it as a module, and mount after selecting a measurable element.
<!doctype html>
<html lang="en">
<meta charset="utf-8">
<title>Juliya example</title>
<p id="title" style="max-width: 220px; font-size: 24px">Keep all your team documents in one place.</p>
<script type="module">
import { mountJuliya } from 'https://cdn.jsdelivr.net/npm/@oddmash/juliya@0.6.0/dist/dom/index.js/+esm';
const title = document.getElementById('title');
mountJuliya(title, { text: title.textContent, locale: 'en' });
</script>
</html>npm and build tools
Install the package and import the DOM adapter. Supply either text in string mode or inline: true for existing markup.
import { mountJuliya } from '@oddmash/juliya/dom';
const controller = mountJuliya(element, { text: "Read every line naturally.", locale: 'en' });
controller.destroy();Language selection
Pass locale as ko, en, ja, zh or zh-Hans. The default is Korean.
Inline markup
Use inline: true to preserve links and emphasis rather than replacing children. Do not pass text simultaneously.
import { mountJuliya } from '@oddmash/juliya/dom';
const controller = mountJuliya(element, { inline: true, locale: 'en' });Options
Common options include locale, strategy, breakLongWords and forcedBreaks. The DOM adapter measures font and content width.
| Option | Required | Default | Purpose |
|---|---|---|---|
text | Conditional | - | Source for string mode; omit in inline mode |
inline | Conditional | false | Set true for existing inline markup |
locale | Optional | ko | Language rules; React also reads the nearest Provider |
strategy | Optional | balanced | Balanced or greedy layout |
breakLongWords | Optional | true | Allow grapheme-safe splits for overlong words |
forcedBreaks | Optional | - | Source UTF-16 boundary offsets |
Update and cleanup
Use controller.update for options, controller.refresh to remeasure and controller.destroy on removal.
controller.update({ text: "Read every line naturally.", locale: 'en' });
controller.refresh();
controller.destroy();Width and text changes
Resize and font events trigger fresh measurements; update the controller when its source text changes.
Observe without owning DOM
Use observeJuliya(element, options, onLayout) when the caller wants to render lines. The layout contains lines and measured.
const controller = observeJuliya(element, { text, locale: 'en' }, ({ lines, measured }) => render(lines, measured));Canvas measurement
Use createCanvasMeasure with a matching font and spacing, then pass the function to the core wrap.
import { createCanvasMeasure } from '@oddmash/juliya/dom';
const measure = createCanvasMeasure({ font: '400 24px sans-serif' });