Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <head>
  <!-- head タグ内でスタイルの読み込み -->
  <link rel="stylesheet" type="text/css" href="https://unpkg.com/palt-typesetting@0.9.0/bundle/typesetter.min.css" />
</head>

<body>
  <p id="target">
    <span class="large en-section"
          >Typesetting Library for Proportional Spacing</span
      >

    <br /><br />──────<br /><br />

    <a
       href="https://github.com/yamatoiizuka/palt-typesetting"
       target="_balnk"
       >Palt Typesetting ↗︎</a
      >は、美しいテキスト表示を実現するためのJavaScriptライブラリです。和欧混植、およびツメ組み(font-feature-settings:
    'palt';)の版面設計において、最大限の力を発揮します。四分アキの自動挿入、カーニング<wbr />ルールの適用、英語のような単語区切りでの改行など、洗練された組版機能を提供します。

    <br /><br />──────<br /><br />

    <span class="en-section">
      <a
         href="https://github.com/yamatoiizuka/palt-typesetting"
         target="_balnk"
         >Palt Typesetting ↗︎</a
        >
      is a JavaScript library designed to achieve beautiful text rendering.
      It excels in mixed typesetting utilizing proportional spacing (enabled
      via font-feature-settings: 'palt';). This library offers sophisticated
      typesetting features, including automatic insertion of quarter em
      spaces, and application of kerning rules, and word-by-word line
      breaking similar to English text style.</span
      >

    <br /><br />─────<br /><br />

    Author: 飯塚大和(Yamato Iizuka)<br /><br />
    GitHub:
    <a href="https://github.com/yamatoiizuka" target="_balnk"
       >@yamatoiizuka</a
      ><br />
    Twitter: <a href="https://twitter.com/yamatoiizuka">@yamatoiizuka</a
    ><br />
    Website: <a href="https://yamatoiizuka.com" target="_blank">yamatoiizuka.com</a>

    <br /><br />

    <a href="https://palt.typesetting.jp" target="_balnk"
       >See an Interactive Demo ↗︎</a
      >
  </p>
  
  <!-- body 閉じタグの前でスクリプトの読み込み -->
  <script src="https://unpkg.com/palt-typesetting@0.9.0/bundle/typesetter.min.js"></script>
</body>
              
            
!

CSS

              
                body {
  -webkit-font-smoothing: antialiased;
  margin: 5rem 3rem;
}

p {
  font-family: aktiv-grotesk, a-otf-gothic-bbb-pr6n, BlinkMacSystemFont, -system-ui, sans-serif;
  font-feature-settings: "palt";
  font-weight: 300;
  font-size: 1.4rem;
  line-height: 2;
  letter-spacing: 0.12em;
  color: rgb(9 9 11);
}

.large {
  font-size: 1.8rem;
}

/*
 * 共通のスタイリング
 */
.typesetting-wrapper {
  /*
   * Safari のフォントレンダリング対策。
   * 英数(.typesetting-latin)で -webkit-text-stroke を使う場合は必須。
   * text-stroke-weight > 0, text-stroke-color: transparent
   */
  -webkit-text-stroke: 0.01em transparent;
}

/*
 * 英数のみのスタイリング
 */
.typesetting-latin {
  /* フォントの拡大・縮小 */
  font-size: 104%;

  /* ベースラインの調整 */
  vertical-align: 0.02em;

  /*
   * 行間の調整。親要素 .typesetting-wrapper の行間と視覚的に合わせます。
   * [.typesetting-wrapper の line-height] ÷ [フォントの拡大率] - [ベースラインの調整値の絶対値] × 2 
   */
  line-height: calc(2 / 1.04 - 0.02 * 2);

  /* 文字間の調整 */
  letter-spacing: 0.05em;

  /* 文字の細らせ・太らせ */
  -webkit-text-stroke: 0.014em rgb(9 9 11);
}

/* 特例文字のスタイリング */
.typesetting-char-bracket {
  opacity: 0.4;
}

.en-section {
  line-height: 1.8;
}

.en-section .typesetting-latin {
  /*
   * 行間の調整。親要素 .typesetting-wrapper の行間と視覚的に合わせます。
   * [.typesetting-wrapper の line-height] ÷ [フォントの拡大率] - [ベースラインの調整値の絶対値] × 2 
   */
  line-height: calc(1.8 / 1.05 - 0.02 * 2);
}

a {
  color: rgb(9 9 11);
  text-decoration: underline;
  text-decoration-thickness: 0.04em;
  text-underline-offset: 0.25em;
}

a:hover {
  text-decoration: none;
}

              
            
!

JS

              
                const options = {
  // 単語や助詞など、語単位での改行を行います。
  useWordBreak: true,

  // 英数を `.typesetting-latin` でラップします。
  wrapLatin: true,
  
    // 特例文字 `char` を `.typesetting-char-[label]` でラップします。
  wrapChars: [
    {
      char: '(',
      label: 'bracket',
    },
    {
      char: ')',
      label: 'bracket',
    },
  ],

  // 罫線などの分離禁則文字を `.typesetting-no-breaks` でラップし、文字間を 0 に設定します。
  noSpaceBetweenNoBreaks: true,

  // 四分アキスペースを自動で挿入します。
  insertThinSpaces: true,

  // 四分アキスペースの幅を設定します。
  thinSpaceWidth: "0.2em",

  // 特定の文字間のカーニングルールを設定します。
  kerningRules: [
    { between: ["美", "し"], value: 60 },
    { between: ["ス", "ト"], value: 120 },
    { between: ["イ", "ブ"], value: 20 },
    { between: ["ブ", "ラ"], value: -30 },
    { between: ["ラ", "リ"], value: 30 },
    { between: ["て", "、"], value: -60 },
    { between: ["す", "。"], value: -120 },
    { between: ["よ", "う"], value: 60 },
    { between: ["う", "な"], value: 40 },
    { between: ["さ", "れ"], value: 20 },
    { between: ["れ", "た"], value: -60 },
    { between: ["供", "し"], value: 40 },
    { between: ["し", "ま"], value: 70 },
  ],
};
const typesetter = new Typesetter(options);
typesetter.renderToSelector("#target");

              
            
!
999px

Console