DocsFrameworks

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.

html
<!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.

ts
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.

ts
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.

OptionRequiredDefaultPurpose
textConditional-Source for string mode; omit in inline mode
inlineConditionalfalseSet true for existing inline markup
localeOptionalkoLanguage rules; React also reads the nearest Provider
strategyOptionalbalancedBalanced or greedy layout
breakLongWordsOptionaltrueAllow grapheme-safe splits for overlong words
forcedBreaksOptional-Source UTF-16 boundary offsets

Update and cleanup

Use controller.update for options, controller.refresh to remeasure and controller.destroy on removal.

ts
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.

ts
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.

ts
import { createCanvasMeasure } from '@oddmash/juliya/dom';
const measure = createCanvasMeasure({ font: '400 24px sans-serif' });