plz-penguin-letters 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,36 @@
1
+ # Changelog
2
+
3
+ Changes that affect people using the library. The newest version is at the top.
4
+
5
+ ## 0.3.0 - 2026-12-04
6
+
7
+ ### Added
8
+
9
+ - **Messages with values in them.** A message like `{count} items` never matched, because the screen says `3 items`. The library now reads the value off the screen and puts it into the original (`{count}개` → `3개`). Only plain `{name}` slots are handled: plural and select messages (`{count, plural, …}`) and rich-text tags (`<b>`) are still skipped, and can be marked with the `data-penguin-letters` attribute instead.
10
+
11
+ ### Changed
12
+
13
+ - **It only looks at what changed.** Every change anywhere on the page used to trigger a search of the whole document on the next frame, so a page with text streaming in (a chat answer, a log) searched everything up to 60 times a second. It now checks only the elements that changed and what is inside them, and does nothing at all for changes inside an `exclude`d area.
14
+
15
+ ## 0.2.0 - 2026-12-03
16
+
17
+ ### Fixed
18
+
19
+ - **React apps could crash.** The library used to take the original text node out of the page. React keeps a reference to that node, so inserting something before it (`{loading && <Spinner />}{label}`) or removing it threw "not a child of this node". The text node now stays where it is and is only emptied.
20
+ - **Endless nesting when `include` contains `span`.** The library's own pieces are `span`s, so it huddled its own output again and again. It no longer looks inside a box it made.
21
+ - **Letters sticking out by about 1px in Firefox** when a line was narrowed a lot. The width is now checked again after the pieces are on the page.
22
+
23
+ ### Changed
24
+
25
+ - **One line by default.** `maxRows` now defaults to `1` (it was `3`): a longer translation is narrowed on a single line. Set `maxRows: 2` or `3` to let it stack.
26
+ - **How the number of rows is chosen.** It takes the fewest rows that keep the letters at or above `squeeze`, instead of the row count with the largest letters. A line that would get very thin is stacked sooner.
27
+ - **Short translations stack as plain lines.** When the translation has four letters or fewer per letter of the original, it is no longer cut into cells (`CO N / FI RM`); it is stacked as lines (`CON / FIRM`).
28
+
29
+ ### Added
30
+
31
+ - **Alignment.** Lines narrower than the original now follow the element's alignment instead of always sitting in the middle. See [How it decides](./README.md#how-it-decides).
32
+ - **`always` option.** Turn it off to huddle only when the longer text would push something or overflow.
33
+
34
+ ## 0.1.0 - 2026-12-03
35
+
36
+ - First release: `installPenguinLetters()` and `penguinLetters()`.
package/README.ko.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  <div align="center">
4
4
 
5
- <img src="./docs/penguin-letters.png" width="340" alt="거친 낙서 두 장. 위: SAVE 때문에 늘어난 버튼이 옆 버튼을 화면 밖으로 밀어 테두리가 찢어졌다. 아래: 같은 화면이 멀쩡하고, SAVE 가 두 줄로 쌓여 다른 버튼과 같은 크기의 버튼 안에 들어가 있다." />
5
+ <img src="./docs/penguin-pair.png" width="560" alt="거친 낙서 네 장이 두 줄로 놓였다. 왼쪽은 글자: SAVE 때문에 늘어난 버튼이 옆 버튼을 화면 밖으로 밀어 테두리가 찢어졌고, 아래는 같은 화면이 멀쩡하며 SAVE 가 두 줄로 쌓여 원래 크기의 버튼 안에 들어가 있다. 오른쪽은 같은 두 장면인데 글자 대신 펭귄 네 마리다: 한 줄로 서면 화면이 찢어지고, 머리를 맞대고 뭉치면 들어간다." />
6
6
 
7
7
  </div>
8
8
 
9
- <p align="center"><sub>뭉치기 전, 그리고 후.</sub></p>
9
+ <p align="center"><sub>뭉치기 전, 그리고 후. 왼쪽은 글자들, 오른쪽은 글자들의 속마음.</sub></p>
10
10
 
11
11
  <h1 align="center">Huddle up plz, penguin letters.</h1>
12
12
 
@@ -32,6 +32,25 @@
32
32
 
33
33
  &nbsp;
34
34
 
35
+ **목차**
36
+
37
+ - [문제](#문제)
38
+ - [펭귄식 해결책](#펭귄식-해결책)
39
+ - [뭉친 모습 더 보기](#뭉친-모습-더-보기)
40
+ - [쓰는 법](#쓰는-법)
41
+ - [어떻게 정하나](#어떻게-정하나)
42
+ - [옵션](#옵션)
43
+ - [몇 줄까지 (`maxRows`)](#몇-줄까지-maxrows)
44
+ - [얼마나 가늘게 (`squeeze`, `fill`)](#얼마나-가늘게-squeeze-fill)
45
+ - [어디를 볼지 (`include`, `exclude`, `always`)](#어디를-볼지-include-exclude-always)
46
+ - [안 뭉쳐도 되는 것들](#안-뭉쳐도-되는-것들)
47
+ - [한 일을 확인하기](#한-일을-확인하기)
48
+ - [진지한 부분](#진지한-부분)
49
+ - [자주 묻는 질문](#자주-묻는-질문)
50
+ - [변경 기록](#변경-기록)
51
+ - [개발](#개발)
52
+ - [라이선스](#라이선스)
53
+
35
54
  ```bash
36
55
  npm install plz-penguin-letters
37
56
  ```
@@ -46,6 +65,8 @@ installPenguinLetters({ base: ko, text: fr });
46
65
 
47
66
  앱 맨 위에 한 줄. 레이아웃은 다시는 안 깨진다.
48
67
 
68
+ &nbsp;
69
+
49
70
  ## 문제
50
71
 
51
72
  화면을 한 언어로 디자인한다. 전부 딱 맞는다. 그리고 독일어 번역이 도착한다.
@@ -54,35 +75,47 @@ installPenguinLetters({ base: ko, text: fr });
54
75
 
55
76
  보통은 유연한 레이아웃이나 짧은 문구, 아니면 긴 회의로 이걸 푼다. 우리는 펭귄에게 물어봤다.
56
77
 
78
+ &nbsp;
79
+
57
80
  ## 펭귄식 해결책
58
81
 
59
82
  황제펭귄은 남극의 겨울을 뭉쳐서 버틴다. 수천 마리가 어깨를 맞대고, 수천 마리가 들어갈 리 없는 자리에 들어간다.
60
83
 
61
84
  글자도 그렇게 할 수 있다.
62
85
 
63
- 원문의 글자 하나가 한 칸이 된다. 번역은 글자 수대로 썰리고, 줄로 쌓이고, 들어갈 때까지 가로로 좁아진다. 낱말이 차지하는 상자는 1픽셀도 변하지 않는다.
86
+ 번역은 원문이 차지하던 바로 그 상자 안에 그려진다. 들어갈 때까지 가로로 좁아지고, 높이는 원문과 똑같이 유지한다. 그래서 글자가 작아지는 대신 길쭉해진다. 허락하면 줄로도 쌓인다. 그때는 원문의 글자 하나가 한 칸이 된다.
64
87
 
65
88
  ```
89
+ 눈치 → PERCEPTIVENESS 한 줄, 아주 가늘게 (기본)
90
+
66
91
  눈치 → PERC EPT
67
- (두 글자) IVEN ESS perceptiveness, 14글자 전원 참석
92
+ (두 글자) IVEN ESS maxRows: 2
68
93
  ```
69
94
 
70
95
  글자는 하나도 안 빠지고, 픽셀은 하나도 안 움직인다.
71
96
 
97
+ &nbsp;
98
+
72
99
  ## 뭉친 모습 더 보기
73
100
 
74
101
  **탭** — 전에도 다섯 개, 후에도 다섯 개. `Benachrichtigungen` 18글자도 그 안에 다 들어 있다.
75
102
 
76
- <img src="./docs/demo-tabs.ko.gif" width="760" alt="탭 바. 전: 긴 번역이 뒤쪽 탭을 화면 밖으로 민다. 후: 탭 다섯 개가 제자리에 있고 글자는 훨씬 작다." />
103
+ <img src="./docs/demo-tabs.ko.gif" width="760" alt="탭 바. 전: 긴 번역이 뒤쪽 탭을 화면 밖으로 민다. 후: 탭 다섯 개가 제자리에 있고 글자는 더 가늘다." />
77
104
 
78
105
  **표 머리글** — 열이 움직이지 않는다. 이렇게 평온했던 적이 없다.
79
106
 
80
107
  <img src="./docs/demo-table.ko.gif" width="760" alt="표. 전: 머리글이 길어져 열이 넓어지다 마지막 열이 잘린다. 후: 열이 움직이지 않는다." />
81
108
 
82
- **큰 낱말 하나 (칸 테두리 표시)** — 뭉친 속을 들여다본 모습.
109
+ **큰 낱말 하나를 쌓은 모습 (`maxRows: 3`, 칸 테두리 표시)** — 뭉친 속을 들여다본 모습.
83
110
 
84
111
  <img src="./docs/demo-word.ko.gif" width="760" alt="120px 의 「설정」. 두 글자가 각각 한 칸이고, Settings · Paramètres · Einstellungen 이 그 안에 쌓인다." />
85
112
 
113
+ **운 좋게 잘린 낱말들 (`maxRows: 2`)** — 글자를 읽지 않고 세어서 자른다. 그런데 가끔 딱 음절 자리에 떨어진다. `암호`는 `PASS / WORD`, `MOT DE / PASSE`, `PASS / WORT`, `MẬT / KHẨU`가 된다.
114
+
115
+ <img src="./docs/demo-lucky.ko.gif" width="760" alt="120px 의 「암호」를 영어, 프랑스어, 독일어, 베트남어로 바꾼다. 두 줄까지 허락하니 Password 는 PASS 위에 WORD, Mot de passe 는 MOT DE 위에 PASSE, Passwort 는 PASS 위에 WORT, Mật khẩu 는 MẬT 위에 KHẨU 로 쌓인다." />
116
+
117
+ &nbsp;
118
+
86
119
  ## 쓰는 법
87
120
 
88
121
  원문이 무엇이었는지 알려 주는 방법이 세 가지다.
@@ -97,6 +130,8 @@ installPenguinLetters({ base: ko, text: fr });
97
130
 
98
131
  언어가 바뀌면 새 파일로 다시 부른다. 앞의 설치는 제 손으로 치우고 나간다.
99
132
 
133
+ 값이 끼어드는 문구도 된다. 화면에 `12 éléments sélectionnés`가 보이고 번역 파일에 `{count} éléments sélectionnés`와 `{count}개 선택`이 있으면, 화면에서 `12`를 읽어 `12개 선택`을 자리로 쓴다.
134
+
100
135
  ### 2. 짝 직접 주기
101
136
 
102
137
  번역 파일이 없으면 짝을 직접 넘긴다. 왼쪽이 화면에 보이는 글, 오른쪽이 원문이다.
@@ -122,7 +157,7 @@ installPenguinLetters();
122
157
  ```js
123
158
  import { penguinLetters } from "plz-penguin-letters";
124
159
 
125
- const undo = penguinLetters(element, { base: "눈치", text: "perceptiveness" });
160
+ const undo = penguinLetters(element, { base: "눈치", text: "perceptiveness", maxRows: 2 });
126
161
  ```
127
162
 
128
163
  ### React
@@ -133,54 +168,145 @@ React용 패키지는 없다. 펭귄은 짐을 가볍게 다닌다.
133
168
  useEffect(() => installPenguinLetters({ base: ko, text: messages }), [messages]);
134
169
  ```
135
170
 
171
+ next-intl이라면 `messages`는 `useMessages()`이고, `base`는 서버 컴포넌트에서 원문 언어 파일을 내려 주면 된다.
172
+
136
173
  두 함수 모두 원래대로 되돌리는 함수를 돌려준다. 부르면 글자들이 다시 흩어진다.
137
174
 
175
+ &nbsp;
176
+
177
+ ## 어떻게 정하나
178
+
179
+ 맡은 요소마다 이 순서로 정한다.
180
+
181
+ 1. **상자.** 원문을 그 요소의 글꼴로, 보이지 않게 놓는다. 그 상자가 자리다. 자리를 차지하는 것은 이것뿐이다.
182
+ 2. **높이.** 글자 크기는 번역의 획 높이가 원문의 획 높이와 똑같아지게 잡는다. 가장 높은 획의 위 끝부터 가장 낮은 획의 아래 끝까지다.
183
+ 3. **줄 수.** 먼저 한 줄로 해 본다. 글자를 `squeeze`보다 더 좁혀야 하고 `maxRows`가 허락하면 두 줄, 그다음 세 줄을 해 본다. 글자가 `squeeze` 밑으로 안 내려가는 가장 적은 줄 수를 고른다.
184
+ 4. **칸이냐 줄이냐.** 번역이 원문 한 글자당 네 글자를 넘으면, 원문 글자 하나가 한 칸이 되고 조각이 그 안에 쌓인다(`PERC EPT / IVEN ESS`). 그보다 적으면 칸마다 한두 글자뿐이라, 칸 없이 줄로만 쌓는다(`ENREG / ISTRER`).
185
+ 5. **폭.** 좁히는 비율은 낱말 전체가 하나를 쓴다. 가장 넓은 조각이 들어가는 값이다. 짧은 조각은 늘이지 않고 자간을 조금 벌린다(`spread`).
186
+ 6. **어느 쪽에 붙일지.** 칸에 든 조각은 칸 가운데에 둔다. 칸 없이 쌓인 줄이 원문보다 좁으면 요소를 따른다. 제목, 여백 있는 버튼, 문장 속 링크는 글 정렬(`text-align`)을 따르고, 버튼 안의 꾸밈 없는 라벨은 이웃이 있는 쪽을 따른다(아이콘 옆이면 아이콘 쪽, 혼자면 가운데).
187
+
188
+ &nbsp;
189
+
190
+ ## 옵션
191
+
192
+ 옵션 없이도 돈다. 모든 옵션은 화면 전체에 적용된다.
193
+
194
+ | 옵션 | 값 | 기본값 | 뜻 |
195
+ | --- | --- | --- | --- |
196
+ | `base`, `text` | 객체 | 없음 | 번역 파일: 원문 언어와 지금 보여 주는 언어 |
197
+ | `pairs` | 객체 | 없음 | `{ "보이는 글": "원문" }`. 번역 파일보다 먼저다 |
198
+ | `include` | CSS 선택자 | 버튼, 링크, 라벨, `th`, `legend`, `summary`, 제목, `role` button · tab · menuitem | 사전으로 찾아볼 요소 |
199
+ | `exclude` | CSS 선택자 | 없음 | 이 선택자에 맞는 요소와 그 안쪽은 건드리지 않는다 |
200
+ | `always` | boolean | `true` | 자리가 넉넉해도 뭉친다 |
201
+ | `maxRows` | 숫자 | `1` | 쌓을 수 있는 줄 수 |
202
+ | `rows` | 숫자 | 자동 | 줄 수를 못박는다 |
203
+ | `squeeze` | 0 – 1 | `0.5` | 이보다 좁혀야 하면 줄을 하나 더 쌓아 본다 |
204
+ | `fill` | boolean | `true` | 높이를 꽉 채운다. 글자가 작아지는 대신 가늘어진다 |
205
+ | `uppercase` | boolean | `true` | 대문자로 그린다 |
206
+ | `spread` | 숫자 (em) | `0.08` | 짧은 조각이 칸을 채우려고 벌릴 수 있는 자간 |
207
+ | `lineGap` | 숫자 (em) | `0.08` | 줄 사이 틈 |
208
+ | `cellGap` | 숫자 (em) | `0` | 칸 사이 틈 |
209
+ | `down` | boolean | `false` | 한 칸을 아래로 다 읽고 다음 칸으로 간다 |
210
+ | `debug` | boolean | `false` | 칸 테두리를 그린다 |
211
+
212
+ ```js
213
+ installPenguinLetters({ base: ko, text: fr, maxRows: 2, exclude: ".editor, [contenteditable]" });
214
+ ```
215
+
216
+ `penguinLetters(element, options)`는 `base`와 `text`를 글로 받고, `maxRows`부터 아래의 옵션을 같이 받는다.
217
+
218
+ ### 몇 줄까지 (`maxRows`)
219
+
220
+ 같은 낱말을 `maxRows`만 바꿔 세 번 그렸다. `약관`은 두 글자고, 독일어로는 `Allgemeine Geschäftsbedingungen` 서른한 글자다.
221
+
222
+ <img src="./docs/demo-rows.ko.gif" width="760" alt="「약관」을 나란히 세 번 그리고 영어, 프랑스어, 독일어, 베트남어로 바꾼다. maxRows 1 은 아주 가는 한 줄, maxRows 2 는 두 줄, maxRows 3 은 독일어에서 세 줄이 되고 글자 폭이 거의 원래대로다." />
223
+
224
+ | | `약관` → `Allgemeine Geschäftsbedingungen` | 좁힌 비율 |
225
+ | --- | --- | --- |
226
+ | `maxRows: 1` (기본) | `ALLGEMEINE GESCHÄFTSBEDINGUNGEN` 한 줄. 바코드처럼 보이지만 한 낱말이 한 줄에 있다 | 0.09 |
227
+ | `maxRows: 2` | `ALLGEMEI NE GESC / HÄFTSBED INGUNGEN` | 0.35 |
228
+ | `maxRows: 3` | `ALLGE MEINE / GESCH ÄFTSB / EDING UNGEN` | 0.76 |
229
+
230
+ 줄은 글자가 아직 `squeeze`보다 가늘 때만 하나 더 쌓는다. 프랑스어 `Conditions générales`는 `maxRows: 3`을 줘도 두 줄에서 멈춘다. 두 줄에서 이미 0.59가 되기 때문이다.
231
+
232
+ 한 줄이 기본인 까닭은 가장 덜 놀라워서다. 줄로 쌓는 것이 이 라이브러리 이름의 유래다. 보고 싶을 때 켠다.
233
+
234
+ `rows`는 고르지 않고 줄 수를 못박는다.
235
+
236
+ ### 얼마나 가늘게 (`squeeze`, `fill`)
237
+
238
+ `squeeze`는 줄을 하나 더 쌓게 만드는 한도다. `0.5`는 "한 줄로 넣으면 원래 폭의 절반보다 가늘어질 때 두 줄을 해 본다"는 뜻이다. `maxRows: 1`이면 해 볼 다른 줄이 없으니, 그 줄이 필요한 만큼 가늘어진다.
239
+
240
+ `fill`은 글자를 원문의 높이 그대로 둔다. 끄면 한도가 진짜 한도가 된다. 글자는 `squeeze`에서 좁아지기를 멈추고 대신 작아진다. 그러면 낱말이 옆의 글보다 낮아 보인다.
241
+
242
+ `uppercase`가 켜져 있는 까닭은 대문자가 높이가 고르고 아래로 내려가는 획이 없어서 상자를 채우기 때문이다. 소문자면 `g`나 `y` 하나가 나머지 글자의 높이를 깎는다.
243
+
244
+ ### 어디를 볼지 (`include`, `exclude`, `always`)
245
+
246
+ `include`는 사전으로 찾아볼 요소의 선택자다. 글을 직접 품은 요소만 맡으니, 버튼이 라벨을 한 번 더 감싸고 있으면(`<button><span>저장</span></button>`) 감싼 요소를 넣는다.
247
+
248
+ ```js
249
+ installPenguinLetters({ base: ko, text: fr, include: "button, a, h1, h2, h3, span" });
250
+ ```
251
+
252
+ 선택자가 넓을수록 더 많이 뭉친다. `p`와 `div`를 넣으면 문장까지 잡힌다.
253
+
254
+ `always: false`는 길어진 글이 이웃을 밀거나, 보이는 상자를 키우거나, 넘칠 때만 뭉친다. 오른쪽이 비어 있는 제목은 그대로 둔다.
255
+
256
+ &nbsp;
257
+
138
258
  ## 안 뭉쳐도 되는 것들
139
259
 
140
260
  - 원문보다 넓지 않은 번역(`확인` → `OK`). 짧은 펭귄은 자유롭게 다닌다.
141
- - 글 말고 다른 것이 같이 든 요소(라벨 옆의 아이콘, 문장 속 링크). 얘도 뭉치게 하고 싶으면 라벨을 `<span>`으로 감싼다.
261
+ - 글 말고 다른 것이 같이 든 요소(라벨 옆의 아이콘, 문장 속 링크). 얘도 뭉치게 하고 싶으면 라벨을 `<span>`으로 감싸고 `include`에 `span`을 넣는다.
262
+ - 복수형·선택·서식이 든 문구(`{count, plural, …}`, `<b>{name}</b>`). 어느 갈래가 화면에 나왔는지 알 수 없으니, 이런 것은 속성으로 표시한다.
142
263
  - `include` 밖의 요소와 `exclude` 안의 요소.
143
264
  - 서로 다른 원문 두 개에 걸리는 글(`Fermer`가 `닫기`이기도 `종료`이기도 할 때). 찍을 수는 없으니, 이런 것은 속성으로 표시한다.
144
265
 
145
- ## 옵션
266
+ &nbsp;
146
267
 
147
- 뭉치는 모양은 조절할 수 있다.
268
+ ## 한 일을 확인하기
148
269
 
149
- | 옵션 | 기본값 | |
150
- | --- | --- | --- |
151
- | `base`, `text` | — | 번역 파일: 원문 언어와 지금 보여 주는 언어. |
152
- | `pairs` | — | `{ "보이는 글": "원문" }`. 번역 파일보다 먼저다. |
153
- | `include` | 버튼, 링크, 라벨, `th`, `legend`, `summary`, 제목, `role` button · tab · menuitem | 사전으로 찾을 자리. |
154
- | `exclude` | — | 건드리지 않을 영역의 선택자. |
155
- | `uppercase` | `true` | 대문자로 그린다. 높이가 고르고 아래로 내려가는 획이 없어서 더 빽빽하게 뭉친다. |
156
- | `rows` | 자동 | 줄 수. 자동이면 글자가 가장 크게 나오는 줄 수를 고른다. |
157
- | `maxRows` | `3` | 자동으로 고를 때의 한도. |
158
- | `squeeze` | `0.5` | 가로로 좁히는 한도. 이보다 좁혀야 하면 줄을 하나 더 쌓아 본다. |
159
- | `fill` | `true` | 원문의 높이를 꽉 채운다. 글자가 작아지는 대신 길쭉해진다. 끄면 `squeeze`까지만 좁히고 글자를 줄인다. |
160
- | `cellGap` | `0` | 칸 사이 틈(그린 글자 크기 대비). |
161
- | `lineGap` | `0.08` | 줄 사이 틈(글자 크기 대비). |
162
- | `spread` | `0.08` | 짧은 조각은 자간을 이만큼까지 벌려 칸을 채운다. |
163
- | `down` | `false` | 가로로 이어 읽지 않고, 한 칸을 아래로 다 읽은 뒤 다음 칸으로 간다. |
164
- | `debug` | `false` | 칸 테두리를 그린다. 누가 어디 섰는지 보인다. |
165
-
166
- `penguinLetters(element, options)`는 `base`와 `text`를 글로 받고, `uppercase`부터 아래의 배치 옵션을 같이 받는다.
270
+ `debug: true`는 칸마다 테두리를 그린다. 누가 어디 섰는지 보인다.
271
+
272
+ 맡은 요소에는 개발자 도구에서 읽을 수 있는 표시도 붙는다.
273
+
274
+ ```html
275
+ <span data-penguin-plan="2x2 69.5px 0.59">
276
+ ```
277
+
278
+ 칸 수 × 줄 수, 글자 크기, 좁힌 비율이다.
279
+
280
+ &nbsp;
167
281
 
168
282
  ## 진지한 부분
169
283
 
170
284
  아이디어는 장난스럽다. 구현은 장난이 아니다.
171
285
 
172
- - **변화를 따라간다.** 나중에 생긴 요소도 처리하고, 프레임워크가 글을 다시 쓰면 다시 배치하고, 요소 크기가 바뀌거나 웹 폰트가 다 읽히면 다시 계산한다.
286
+ - **프레임워크와 싸우지 않는다.** 원래 글 노드를 화면에서 떼지 않는다. 그래서 React가 그 글을 고치고, 그 옆에 끼우고, 지워도 터지지 않는다. 글이 바뀌면 다시 뭉친다.
287
+ - **변화를 따라가되, 바뀐 자리만 본다.** 나중에 생긴 요소도 처리하고, 요소 크기가 바뀌거나 웹 폰트가 다 읽히면 다시 계산한다. 무언가 바뀌면 그 자리만 다시 보니, 채팅에 글이 흘러나와도 문서 전체를 훑지 않는다. 그런 영역을 `exclude`에 넣으면 거기서는 아예 일하지 않는다.
288
+ - **낭독기**는 번역을 평범한 낱말 하나로 읽는다. 조각은 낭독기에 숨긴다.
173
289
  - **서버 렌더링**: `document`가 없는 곳에서 부르면 아무것도 하지 않는다.
174
290
  - **테스트**: Chromium, Firefox, WebKit에서 돌린다. `Intl.Segmenter`가 필요하다.
175
291
  - **글자 수로 자른다.** 음절 자리가 아니다. `PERC / IVEN`은 사전의 하이픈 자리가 아니다. 펭귄은 하이픈을 안 쓴다.
176
292
 
293
+ &nbsp;
294
+
177
295
  ## 자주 묻는 질문
178
296
 
179
297
  **실서비스에 써도 되나요?**
180
298
  제목이나 큰 버튼에서는 의외로 의도한 디자인처럼 보인다. 14px 본문이라면 디자이너에게 먼저 물어보자.
181
299
 
182
300
  **14px에서도 읽히나요?**
183
- 글자가 아주 작아진다. 한 글자도 빠지지 않았다. 세어 봤다.
301
+ 글자가 아주 가늘어진다. 한 글자도 빠지지 않았다. 세어 봤다.
302
+
303
+ &nbsp;
304
+
305
+ ## 변경 기록
306
+
307
+ 버전마다 바뀐 것은 [CHANGELOG.md](./CHANGELOG.md)에 있다(영어). 최신 버전이 맨 위다.
308
+
309
+ &nbsp;
184
310
 
185
311
  ## 개발
186
312
 
@@ -191,6 +317,8 @@ npm run build # dist/esm + dist/cjs, 타입 선언 포함
191
317
  npm run record # 리드미 움짤(docs/demo*.gif) 다시 만들기 — ffmpeg 필요
192
318
  ```
193
319
 
320
+ &nbsp;
321
+
194
322
  ## 라이선스
195
323
 
196
324
  MIT. 펭귄은 한 마리도 눌리지 않았다. 글자들은 자원했다.
package/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  <div align="center">
4
4
 
5
- <img src="./docs/penguin-letters.png" width="340" alt="Two rough sketches. Top: a button stretched by the word SAVE shoves its neighbour through the edge of the screen, tearing it. Bottom: the same screen intact, with SAVE stacked in two rows inside a button the same size as the others." />
5
+ <img src="./docs/penguin-pair.png" width="560" alt="Four rough sketches in two columns. Left, with letters: a button stretched by the word SAVE shoves its neighbour through the edge of the screen, tearing it; below, the same screen intact with SAVE stacked in two rows inside a button of the original size. Right, the same two scenes with four penguins instead of letters: standing in a row they tear the screen, huddled head to head they fit." />
6
6
 
7
7
  </div>
8
8
 
9
- <p align="center"><sub>Before the huddle, and after.</sub></p>
9
+ <p align="center"><sub>Before the huddle, and after. Left: the letters. Right: what they are thinking.</sub></p>
10
10
 
11
11
  <h1 align="center">Huddle up plz, penguin letters.</h1>
12
12
 
@@ -32,6 +32,25 @@
32
32
 
33
33
  &nbsp;
34
34
 
35
+ **Contents**
36
+
37
+ - [The problem](#the-problem)
38
+ - [The penguin solution](#the-penguin-solution)
39
+ - [More huddles](#more-huddles)
40
+ - [Usage](#usage)
41
+ - [How it decides](#how-it-decides)
42
+ - [Options](#options)
43
+ - [How many rows (`maxRows`)](#how-many-rows-maxrows)
44
+ - [How thin (`squeeze`, `fill`)](#how-thin-squeeze-fill)
45
+ - [Where to look (`include`, `exclude`, `always`)](#where-to-look-include-exclude-always)
46
+ - [Who gets to roam free](#who-gets-to-roam-free)
47
+ - [Seeing what it did](#seeing-what-it-did)
48
+ - [The serious part](#the-serious-part)
49
+ - [FAQ](#faq)
50
+ - [Changelog](#changelog)
51
+ - [Development](#development)
52
+ - [License](#license)
53
+
35
54
  ```bash
36
55
  npm install plz-penguin-letters
37
56
  ```
@@ -46,6 +65,8 @@ installPenguinLetters({ base: en, text: fr });
46
65
 
47
66
  One line at the top of your app. Your layout will never break again.
48
67
 
68
+ &nbsp;
69
+
49
70
  ## The problem
50
71
 
51
72
  You design a screen in one language. Everything fits. Then the German translation arrives.
@@ -54,35 +75,47 @@ You design a screen in one language. Everything fits. Then the German translatio
54
75
 
55
76
  Most people fix this with flexible layouts, shorter copy, or a long meeting. We asked the penguins.
56
77
 
78
+ &nbsp;
79
+
57
80
  ## The penguin solution
58
81
 
59
82
  Emperor penguins survive the Antarctic winter by huddling: thousands of them, shoulder to shoulder, in a space that should not hold thousands of penguins.
60
83
 
61
84
  Letters can do that too.
62
85
 
63
- Each letter of the original word becomes a cell. The translation is chopped up by letter count, stacked in rows, and narrowed until it fits. The box the word takes up does not change by a single pixel.
86
+ The translation is drawn in the exact box the original word took. It is narrowed until it fits, and it keeps the full height of the original, so the letters get tall and thin rather than small. If you let it, it also stacks into rows, with each letter of the original word as one cell.
64
87
 
65
88
  ```
89
+ FAQ → FOIRE AUX QUESTIONS one line, very thin (default)
90
+
66
91
  FAQ → FOI RE AUX
67
- (3 letters) QUE STI ONS "Foire aux questions", all of it
92
+ (3 letters) QUE STI ONS maxRows: 2
68
93
  ```
69
94
 
70
95
  Not one letter is dropped, and not one pixel moves.
71
96
 
97
+ &nbsp;
98
+
72
99
  ## More huddles
73
100
 
74
101
  **Tabs** — five tabs before, five tabs after. `Benachrichtigungen` is in there too, all 18 letters.
75
102
 
76
- <img src="./docs/demo-tabs.gif" width="760" alt="A tab bar. Before: longer translations push the last tabs off the edge. After: all five tabs stay where they were, in much smaller letters." />
103
+ <img src="./docs/demo-tabs.gif" width="760" alt="A tab bar. Before: longer translations push the last tabs off the edge. After: all five tabs stay where they were, in thinner letters." />
77
104
 
78
105
  **Table headers** — the columns have not moved. They have never been so calm.
79
106
 
80
107
  <img src="./docs/demo-table.gif" width="760" alt="A table. Before: longer headers widen the columns until the last one is cut off. After: the columns do not move." />
81
108
 
82
- **One big word, with the cells outlined** — a look inside the huddle.
109
+ **One big word, stacked (`maxRows: 3`, cells outlined)** — a look inside the huddle.
83
110
 
84
111
  <img src="./docs/demo-word.gif" width="760" alt="The word FAQ at 120px. Each of its three letters is a cell, and Foire aux questions, Häufig gestellte Fragen and Câu hỏi thường gặp are stacked inside them." />
85
112
 
113
+ **Lucky cuts (`maxRows: 2`)** — words are cut by counting letters, not by reading them. Sometimes the count lands exactly on a syllable: `Hi` becomes `BON / JOUR`, `SER / VUS` and `XIN / CHÀO`.
114
+
115
+ <img src="./docs/demo-lucky.gif" width="760" alt="The word Hi at 120px, switched to French, German and Vietnamese. With two rows allowed, Bonjour is stacked as BON over JOUR, Servus as SER over VUS, and Xin chào as XIN over CHÀO." />
116
+
117
+ &nbsp;
118
+
86
119
  ## Usage
87
120
 
88
121
  There are three ways to tell it what the original word was.
@@ -97,6 +130,8 @@ The two files are matched by key (nested keys are fine). When a button shows `En
97
130
 
98
131
  When the language changes, call it again with the new file. The previous install cleans up after itself.
99
132
 
133
+ Messages with values in them work too. If the screen says `12 éléments sélectionnés`, the files say `{count} éléments sélectionnés` and `{count} selected`, it reads the `12` off the screen and uses `12 selected` as the footprint.
134
+
100
135
  ### 2. Pairs
101
136
 
102
137
  No translation files? Hand over the pairs yourself — shown text on the left, original on the right.
@@ -122,7 +157,7 @@ An element with the attribute is always handled, wherever it is.
122
157
  ```js
123
158
  import { penguinLetters } from "plz-penguin-letters";
124
159
 
125
- const undo = penguinLetters(element, { base: "FAQ", text: "Foire aux questions" });
160
+ const undo = penguinLetters(element, { base: "FAQ", text: "Foire aux questions", maxRows: 2 });
126
161
  ```
127
162
 
128
163
  ### React
@@ -133,54 +168,145 @@ There is no React package. Penguins travel light.
133
168
  useEffect(() => installPenguinLetters({ base: en, text: messages }), [messages]);
134
169
  ```
135
170
 
171
+ With next-intl, `messages` is `useMessages()`, and `base` is the original language's file passed down from a server component.
172
+
136
173
  Both functions return a function that puts everything back and lets the letters spread out again.
137
174
 
175
+ &nbsp;
176
+
177
+ ## How it decides
178
+
179
+ For every element it handles, in this order:
180
+
181
+ 1. **The box.** The original word is laid out invisibly, in the element's own font. That box is the footprint, and it is the only thing that takes up space.
182
+ 2. **The height.** The font size is chosen so the letters are exactly as tall as the original's ink, from the top of the tallest stroke to the bottom of the lowest.
183
+ 3. **The rows.** One row is tried first. If the letters would have to be narrower than `squeeze`, and `maxRows` allows it, a second row is tried, then a third. The fewest rows that keep the letters at or above `squeeze` win.
184
+ 4. **Cells or lines.** With more than four letters of translation per letter of the original, each original letter becomes a cell and the pieces are stacked inside it (`FOI RE AUX / QUE STI ONS`). With fewer, cells would hold one or two letters each, so it stacks plain lines instead (`ENREG / ISTRER`).
185
+ 5. **The width.** One narrowing ratio is used for the whole word: the one that makes the widest piece fit. Shorter pieces get a little letter-spacing (`spread`) instead of being stretched.
186
+ 6. **The side.** Pieces in cells sit in the middle of their cell. Plain lines narrower than the original follow the element: `text-align` for headings, padded buttons and links inside a sentence; for a bare label inside a button, the side its neighbours are on (next to the icon, or centred if it is alone).
187
+
188
+ &nbsp;
189
+
190
+ ## Options
191
+
192
+ It works with no options at all. Every option applies to the whole page.
193
+
194
+ | Option | Value | Default | Meaning |
195
+ | --- | --- | --- | --- |
196
+ | `base`, `text` | object | none | Translation files: the original language, and the one on screen |
197
+ | `pairs` | object | none | `{ "shown text": "original" }`. Wins over the files |
198
+ | `include` | CSS selector | buttons, links, labels, `th`, `legend`, `summary`, headings, `role` button · tab · menuitem | Which elements are looked up in the dictionary |
199
+ | `exclude` | CSS selector | none | Elements matching this, and everything inside them, are left alone |
200
+ | `always` | boolean | `true` | Huddle even when there is room to grow |
201
+ | `maxRows` | number | `1` | How many rows it may stack |
202
+ | `rows` | number | auto | Force an exact number of rows |
203
+ | `squeeze` | 0 – 1 | `0.5` | How narrow letters may get before another row is tried |
204
+ | `fill` | boolean | `true` | Keep the full height; letters get thin instead of small |
205
+ | `uppercase` | boolean | `true` | Draw in capitals |
206
+ | `spread` | number (em) | `0.08` | Letter-spacing short pieces may get to fill their cell |
207
+ | `lineGap` | number (em) | `0.08` | Gap between rows |
208
+ | `cellGap` | number (em) | `0` | Gap between cells |
209
+ | `down` | boolean | `false` | Read down each cell, then move to the next |
210
+ | `debug` | boolean | `false` | Outline the cells |
211
+
212
+ ```js
213
+ installPenguinLetters({ base: en, text: fr, maxRows: 2, exclude: ".editor, [contenteditable]" });
214
+ ```
215
+
216
+ `penguinLetters(element, options)` takes `base` and `text` as strings, plus everything from `maxRows` down.
217
+
218
+ ### How many rows (`maxRows`)
219
+
220
+ The same word three times, with only `maxRows` changed. `T&C` is three letters; the German for it is `Allgemeine Geschäftsbedingungen`, thirty-one.
221
+
222
+ <img src="./docs/demo-rows.gif" width="760" alt="The label T&C drawn three times side by side, switched between French, German and Vietnamese. With maxRows 1 the translation is one very thin line. With maxRows 2 it is two rows. With maxRows 3 the German one takes three rows and the letters are almost their natural width." />
223
+
224
+ | | `T&C` → `Allgemeine Geschäftsbedingungen` | Narrowed to |
225
+ | --- | --- | --- |
226
+ | `maxRows: 1` (default) | `ALLGEMEINE GESCHÄFTSBEDINGUNGEN` on one line. Reads like a barcode, but it is one word on one line | 0.13 |
227
+ | `maxRows: 2` | `ALLGE MEINE GESC / HÄFTSB EDING UNGEN` | 0.44 |
228
+ | `maxRows: 3` | `ALLG EME INE / GES CHÄF TSB / EDIN GUN GEN` | 0.96 |
229
+
230
+ A row is added only while the letters are still narrower than `squeeze`. The French `Conditions générales` stops at two rows even with `maxRows: 3`, because two rows already bring it to 0.61.
231
+
232
+ One line is the default because it is the least surprising. Stacking is where the library gets its name; turn it on when you want to see it.
233
+
234
+ `rows` skips the choice and forces a number.
235
+
236
+ ### How thin (`squeeze`, `fill`)
237
+
238
+ `squeeze` is the limit that triggers another row: `0.5` means "if one line would be narrower than half its natural width, try two". With `maxRows: 1` there is no other row to try, so the line simply gets as thin as it must.
239
+
240
+ `fill` keeps the letters at the full height of the original. Turn it off and the limit becomes a hard one: letters stop narrowing at `squeeze` and get smaller instead, which leaves the word shorter than its neighbours.
241
+
242
+ `uppercase` is on because capitals have even heights and no descenders, so they fill the box. With lowercase, a `g` or `y` takes height away from every other letter.
243
+
244
+ ### Where to look (`include`, `exclude`, `always`)
245
+
246
+ `include` is a selector for the elements that are looked up in the dictionary. Only elements that hold plain text directly are handled, so if your buttons wrap their label (`<button><span>Save</span></button>`), add the wrapper:
247
+
248
+ ```js
249
+ installPenguinLetters({ base: en, text: fr, include: "button, a, h1, h2, h3, span" });
250
+ ```
251
+
252
+ The wider the selector, the more gets huddled. `p` and `div` will catch whole sentences.
253
+
254
+ `always: false` huddles only when the longer text would actually push a neighbour, grow a visible box, or overflow. A heading with empty space to its right is then left alone.
255
+
256
+ &nbsp;
257
+
138
258
  ## Who gets to roam free
139
259
 
140
260
  - A translation that is not wider than the original (`Cancel` → `Hủy`). Short penguins roam free.
141
- - Elements with anything other than plain text inside (an icon next to the label, a link inside a sentence). Wrap the label in a `<span>` if you want it huddled too.
261
+ - Elements with anything other than plain text inside (an icon next to the label, a link inside a sentence). Wrap the label in a `<span>` and add `span` to `include` if you want it huddled too.
262
+ - Plural, select and rich-text messages (`{count, plural, …}`, `<b>{name}</b>`). It can't work out which branch is on screen; mark those with the attribute.
142
263
  - Anything outside `include`, and anything inside `exclude`.
143
264
  - A text that maps to two different originals (`Fermer` for both `Close` and `Quit`). It can't guess; mark those with the attribute.
144
265
 
145
- ## Options
266
+ &nbsp;
146
267
 
147
- Every huddle can be tuned.
268
+ ## Seeing what it did
148
269
 
149
- | Option | Default | |
150
- | --- | --- | --- |
151
- | `base`, `text` | — | Translation files: the original language, and the one on screen. |
152
- | `pairs` | — | `{ "shown text": "original" }`. Wins over the files. |
153
- | `include` | buttons, links, labels, `th`, `legend`, `summary`, headings, `role` button · tab · menuitem | Where to look when matching by dictionary. |
154
- | `exclude` | — | Selector for areas to leave alone. |
155
- | `uppercase` | `true` | Draws in capitals — even heights and no descenders, so the huddle is tighter. |
156
- | `rows` | auto | Number of rows. Auto picks the one that gives the largest letters. |
157
- | `maxRows` | `3` | Limit for auto. |
158
- | `squeeze` | `0.5` | How narrow letters may get before another row is tried. |
159
- | `fill` | `true` | Fills the full height of the original: letters get tall and thin instead of small. Turn it off to stop narrowing at `squeeze` and shrink instead. |
160
- | `cellGap` | `0` | Gap between cells, in em of the drawn size. |
161
- | `lineGap` | `0.08` | Gap between rows, in em. |
162
- | `spread` | `0.08` | Short pieces get up to this much letter-spacing to fill their cell. |
163
- | `down` | `false` | Read down each cell before moving to the next, instead of across. |
164
- | `debug` | `false` | Outlines the cells, so you can see who stands where. |
165
-
166
- `penguinLetters(element, options)` takes `base` and `text` as strings, plus the layout options from `uppercase` down.
270
+ `debug: true` outlines every cell, so you can see who stands where.
271
+
272
+ Each handled element also gets a marker you can read in the inspector:
273
+
274
+ ```html
275
+ <span data-penguin-plan="3x2 57.1px 0.60">
276
+ ```
277
+
278
+ That is cells × rows, the font size, and the narrowing ratio.
279
+
280
+ &nbsp;
167
281
 
168
282
  ## The serious part
169
283
 
170
284
  The idea is playful. The implementation is not kidding.
171
285
 
172
- - **It follows changes.** Elements added later are picked up, text rewritten by your framework is laid out again, and everything is recalculated when the element is resized or a web font finishes loading.
286
+ - **It does not fight your framework.** The original text node stays in the page, so React can keep updating it, inserting next to it and removing it. When the text changes, the huddle is redone.
287
+ - **It follows changes, and only the changes.** Elements added later are picked up, and a huddle is recalculated when its element is resized or a web font finishes loading. When something changes it looks at that spot only, so text streaming into a chat does not make it search the whole page. Put such areas in `exclude` and it does nothing for them at all.
288
+ - **Screen readers** get the translation as one normal word. The pieces are hidden from them.
173
289
  - **Server rendering**: calling it where there is no `document` does nothing.
174
- - **Tested** on Chromium, Firefox and WebKit, Needs `Intl.Segmenter`.
290
+ - **Tested** on Chromium, Firefox and WebKit. Needs `Intl.Segmenter`.
175
291
  - **Words are cut by letter count**, not by syllable. `FOI / RE` is not where a dictionary would hyphenate. Penguins do not hyphenate.
176
292
 
293
+ &nbsp;
294
+
177
295
  ## FAQ
178
296
 
179
297
  **Should I use this in production?**
180
298
  On a headline or a big button, it looks surprisingly intentional. On 14px body text, ask your designer first.
181
299
 
182
300
  **Is it readable at 14px?**
183
- The letters get very small. They are all there. We counted.
301
+ The letters get very thin. They are all there. We counted.
302
+
303
+ &nbsp;
304
+
305
+ ## Changelog
306
+
307
+ What changed in each version is in [CHANGELOG.md](./CHANGELOG.md). The newest version is at the top.
308
+
309
+ &nbsp;
184
310
 
185
311
  ## Development
186
312
 
@@ -191,6 +317,8 @@ npm run build # dist/esm + dist/cjs with type declarations
191
317
  npm run record # re-record the README GIFs (docs/demo*.gif) — needs ffmpeg
192
318
  ```
193
319
 
320
+ &nbsp;
321
+
194
322
  ## License
195
323
 
196
324
  MIT. No penguins were squeezed. The letters volunteered.
@@ -26,6 +26,8 @@ export interface InstallOptions extends PlanOptions {
26
26
  include?: string;
27
27
  /** 건드리지 않을 요소 선택자 — 그 안쪽까지 뺀다. */
28
28
  exclude?: string;
29
+ /** 자리가 넉넉해도 원문 자리에 뭉친다. 끄면 길어진 글이 무언가를 밀거나 넘칠 때만 뭉친다(오른쪽이 빈 제목·라벨은 그대로 둔다). 기본 켬. */
30
+ always?: boolean;
29
31
  /** 대문자로 바꿔 그린다. 기본 켬. */
30
32
  uppercase?: boolean;
31
33
  /** 칸 테두리를 그린다. */