@nice2dev/ui-graphics 1.3.15 → 1.3.16

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.
Files changed (294) hide show
  1. package/CHANGELOG.md +9 -0
  2. package/dist/cjs/animation/AnimatedPerson.js +470 -143
  3. package/dist/cjs/animation/AnimationEditor.js +289 -101
  4. package/dist/cjs/animation/Audience.js +83 -61
  5. package/dist/cjs/animation/BodyRenderer.js +69 -28
  6. package/dist/cjs/animation/animationHelper.js +281 -288
  7. package/dist/cjs/animation/characterTypes.js +200 -203
  8. package/dist/cjs/animation/choreoDSL.js +205 -219
  9. package/dist/cjs/animation/choreography.js +4 -32
  10. package/dist/cjs/animation/karaokeIntegration.js +68 -77
  11. package/dist/cjs/animation/lottieExport.js +108 -114
  12. package/dist/cjs/animation/motionPath.js +225 -248
  13. package/dist/cjs/animation/physics.js +227 -254
  14. package/dist/cjs/animation/rig/RigPlayer.js +53 -56
  15. package/dist/cjs/animation/rig/RiggedBody.js +71 -26
  16. package/dist/cjs/animation/rig/choreoRigBridge.js +72 -77
  17. package/dist/cjs/animation/rig/ik.js +13 -18
  18. package/dist/cjs/animation/rig/poseOps.js +34 -41
  19. package/dist/cjs/animation/rig/presets.js +64 -72
  20. package/dist/cjs/animation/rig/rigMath.js +25 -32
  21. package/dist/cjs/animation/rig/rigTypes.js +59 -63
  22. package/dist/cjs/animation/shapes/arms.js +31 -13
  23. package/dist/cjs/animation/shapes/eyes.js +129 -47
  24. package/dist/cjs/animation/shapes/hair.js +72 -45
  25. package/dist/cjs/animation/shapes/heads.js +131 -57
  26. package/dist/cjs/animation/shapes/headwear.js +47 -38
  27. package/dist/cjs/animation/shapes/legs.js +31 -13
  28. package/dist/cjs/animation/shapes/mouths.js +120 -44
  29. package/dist/cjs/animation/shapes/noses.js +80 -25
  30. package/dist/cjs/animation/shapes/outfits.js +101 -39
  31. package/dist/cjs/animation/shapes/torsos.js +15 -11
  32. package/dist/cjs/animation/spineExport.js +103 -121
  33. package/dist/cjs/core/LocalUI.js +108 -43
  34. package/dist/cjs/core/NiceBrushEngine.js +758 -552
  35. package/dist/cjs/core/collaboration.js +249 -251
  36. package/dist/cjs/core/colorBlindness.js +100 -115
  37. package/dist/cjs/core/dragDrop.js +155 -158
  38. package/dist/cjs/core/editorAsk.js +51 -41
  39. package/dist/cjs/core/fixes.js +140 -171
  40. package/dist/cjs/core/gridGuides.js +166 -201
  41. package/dist/cjs/core/historyVisual.js +156 -135
  42. package/dist/cjs/core/i18n.js +13 -14
  43. package/dist/cjs/core/integrations.js +238 -249
  44. package/dist/cjs/core/minimap.js +149 -151
  45. package/dist/cjs/core/plugins.js +98 -113
  46. package/dist/cjs/core/rtl.js +71 -83
  47. package/dist/cjs/core/shortcuts.js +196 -225
  48. package/dist/cjs/core/theme.js +142 -149
  49. package/dist/cjs/core/yjsCollaboration.js +232 -293
  50. package/dist/cjs/design/design-tools.js +12 -22
  51. package/dist/cjs/font/NiceFontEditor.js +877 -316
  52. package/dist/cjs/font/fontFormatUtils.js +388 -448
  53. package/dist/cjs/game/GameAsset2dEditor.js +1201 -392
  54. package/dist/cjs/game/GameAsset2dEditor.module.css.js +146 -5
  55. package/dist/cjs/game/gameAssetTypes.js +7 -16
  56. package/dist/cjs/game/gameAssetUtils.js +390 -413
  57. package/dist/cjs/game/useGameAssetEditor.js +820 -763
  58. package/dist/cjs/index.js +81 -84
  59. package/dist/cjs/nice2dev-ui-graphics.css +1 -1
  60. package/dist/cjs/node_modules/lib0/array.js +8 -70
  61. package/dist/cjs/node_modules/lib0/binary.js +3 -20
  62. package/dist/cjs/node_modules/lib0/broadcastchannel.js +24 -86
  63. package/dist/cjs/node_modules/lib0/buffer.js +15 -82
  64. package/dist/cjs/node_modules/lib0/conditions.js +3 -16
  65. package/dist/cjs/node_modules/lib0/decoding.js +108 -287
  66. package/dist/cjs/node_modules/lib0/dom.js +14 -44
  67. package/dist/cjs/node_modules/lib0/encoding.js +68 -418
  68. package/dist/cjs/node_modules/lib0/environment.js +26 -92
  69. package/dist/cjs/node_modules/lib0/error.js +5 -29
  70. package/dist/cjs/node_modules/lib0/function.js +27 -66
  71. package/dist/cjs/node_modules/lib0/iterator.js +8 -33
  72. package/dist/cjs/node_modules/lib0/logging.common.js +12 -22
  73. package/dist/cjs/node_modules/lib0/logging.js +32 -71
  74. package/dist/cjs/node_modules/lib0/map.js +16 -86
  75. package/dist/cjs/node_modules/lib0/math.js +3 -32
  76. package/dist/cjs/node_modules/lib0/number.js +4 -15
  77. package/dist/cjs/node_modules/lib0/object.js +14 -88
  78. package/dist/cjs/node_modules/lib0/observable.js +38 -78
  79. package/dist/cjs/node_modules/lib0/pair.js +3 -20
  80. package/dist/cjs/node_modules/lib0/prng.js +8 -77
  81. package/dist/cjs/node_modules/lib0/promise.js +6 -30
  82. package/dist/cjs/node_modules/lib0/random.js +8 -23
  83. package/dist/cjs/node_modules/lib0/schema.js +313 -687
  84. package/dist/cjs/node_modules/lib0/set.js +3 -10
  85. package/dist/cjs/node_modules/lib0/storage.js +20 -55
  86. package/dist/cjs/node_modules/lib0/string.js +17 -72
  87. package/dist/cjs/node_modules/lib0/symbol.js +2 -12
  88. package/dist/cjs/node_modules/lib0/time.js +2 -15
  89. package/dist/cjs/node_modules/lib0/trait/equality.js +3 -28
  90. package/dist/cjs/node_modules/lib0/url.js +4 -18
  91. package/dist/cjs/node_modules/lib0/webcrypto.js +2 -5
  92. package/dist/cjs/node_modules/y-protocols/auth.js +5 -19
  93. package/dist/cjs/node_modules/y-protocols/awareness.js +53 -116
  94. package/dist/cjs/node_modules/y-protocols/sync.js +16 -103
  95. package/dist/cjs/node_modules/y-websocket/src/y-websocket.js +77 -219
  96. package/dist/cjs/node_modules/yjs/dist/yjs.js +2128 -4868
  97. package/dist/cjs/photo/FilterThumb.js +37 -25
  98. package/dist/cjs/photo/NiceAITools.js +679 -467
  99. package/dist/cjs/photo/PhotoEditor.js +34 -20
  100. package/dist/cjs/photo/PhotoEditor.module.css.js +296 -5
  101. package/dist/cjs/photo/PhotoEditorCanvas.js +250 -91
  102. package/dist/cjs/photo/PhotoEditorLeftPanel.js +1086 -224
  103. package/dist/cjs/photo/PhotoEditorToolbar.js +135 -19
  104. package/dist/cjs/photo/photoEditorActions.js +89 -72
  105. package/dist/cjs/photo/photoEditorTypes.js +29 -32
  106. package/dist/cjs/photo/photoFilters.js +959 -985
  107. package/dist/cjs/photo/photoOverlays.js +899 -945
  108. package/dist/cjs/photo/photoSelection.js +427 -499
  109. package/dist/cjs/photo/usePhotoEditor.js +739 -741
  110. package/dist/cjs/pixel/HSVPicker.js +191 -175
  111. package/dist/cjs/pixel/PixelEditor.js +159 -48
  112. package/dist/cjs/pixel/PixelEditor.module.css.js +209 -5
  113. package/dist/cjs/pixel/PixelEditorCanvas.js +29 -16
  114. package/dist/cjs/pixel/PixelEditorMenuBar.js +160 -162
  115. package/dist/cjs/pixel/PixelEditorRightPanel.js +377 -45
  116. package/dist/cjs/pixel/PixelEditorStatusBar.js +47 -20
  117. package/dist/cjs/pixel/PixelEditorTimeline.js +106 -23
  118. package/dist/cjs/pixel/PixelEditorToolbar.js +99 -21
  119. package/dist/cjs/pixel/SpriteGeneratorPanel.js +483 -303
  120. package/dist/cjs/pixel/animalGeneratorPresets.js +776 -601
  121. package/dist/cjs/pixel/asepriteFormat.js +511 -560
  122. package/dist/cjs/pixel/buildingGeneratorPresets.js +693 -520
  123. package/dist/cjs/pixel/characterGeneratorPresets.js +644 -544
  124. package/dist/cjs/pixel/pixel-pro.js +52 -63
  125. package/dist/cjs/pixel/pixelEditorExports.js +388 -428
  126. package/dist/cjs/pixel/pixelEditorTypes.js +91 -108
  127. package/dist/cjs/pixel/pixelEditorUtils.js +519 -561
  128. package/dist/cjs/pixel/spriteGeneratorCore.js +206 -257
  129. package/dist/cjs/pixel/usePixelEditor.js +1321 -1343
  130. package/dist/cjs/texture/Nice3DTexturePainter.js +707 -440
  131. package/dist/cjs/ui/NiceUIDesigner.js +954 -527
  132. package/dist/cjs/vector/NiceSvgToCode.js +586 -446
  133. package/dist/cjs/vector/VectorEditor.js +290 -117
  134. package/dist/cjs/vector/VectorEditor.module.css.js +86 -5
  135. package/dist/cjs/vector/VectorEditorMenuBar.js +333 -275
  136. package/dist/cjs/vector/VectorEditorRightPanel.js +1094 -371
  137. package/dist/cjs/vector/VectorEditorShapeRenderer.js +198 -60
  138. package/dist/cjs/vector/VectorEditorStatusBar.js +39 -13
  139. package/dist/cjs/vector/useVectorEditor.js +848 -889
  140. package/dist/cjs/vector/vectorAnimation.js +110 -137
  141. package/dist/cjs/vector/vectorBooleanOps.js +398 -485
  142. package/dist/cjs/vector/vectorEditorExport.js +201 -203
  143. package/dist/cjs/vector/vectorEditorImport.js +173 -189
  144. package/dist/cjs/vector/vectorEditorTypes.js +42 -49
  145. package/dist/cjs/vector/vectorGradients.js +151 -174
  146. package/dist/cjs/vector/vectorIconExport.js +52 -59
  147. package/dist/cjs/vector/vectorIconImport.js +169 -219
  148. package/dist/esm/animation/AnimatedPerson.js +470 -141
  149. package/dist/esm/animation/AnimationEditor.js +290 -100
  150. package/dist/esm/animation/Audience.js +83 -59
  151. package/dist/esm/animation/BodyRenderer.js +71 -25
  152. package/dist/esm/animation/animationHelper.js +284 -287
  153. package/dist/esm/animation/characterTypes.js +204 -202
  154. package/dist/esm/animation/choreoDSL.js +212 -218
  155. package/dist/esm/animation/choreography.js +8 -31
  156. package/dist/esm/animation/karaokeIntegration.js +74 -76
  157. package/dist/esm/animation/lottieExport.js +112 -113
  158. package/dist/esm/animation/motionPath.js +235 -247
  159. package/dist/esm/animation/physics.js +235 -253
  160. package/dist/esm/animation/rig/RigPlayer.js +53 -54
  161. package/dist/esm/animation/rig/RiggedBody.js +71 -24
  162. package/dist/esm/animation/rig/choreoRigBridge.js +74 -76
  163. package/dist/esm/animation/rig/ik.js +14 -17
  164. package/dist/esm/animation/rig/poseOps.js +37 -40
  165. package/dist/esm/animation/rig/presets.js +70 -71
  166. package/dist/esm/animation/rig/rigMath.js +28 -31
  167. package/dist/esm/animation/rig/rigTypes.js +62 -62
  168. package/dist/esm/animation/shapes/arms.js +32 -12
  169. package/dist/esm/animation/shapes/eyes.js +135 -46
  170. package/dist/esm/animation/shapes/hair.js +80 -44
  171. package/dist/esm/animation/shapes/heads.js +140 -56
  172. package/dist/esm/animation/shapes/headwear.js +54 -37
  173. package/dist/esm/animation/shapes/legs.js +32 -12
  174. package/dist/esm/animation/shapes/mouths.js +127 -43
  175. package/dist/esm/animation/shapes/noses.js +87 -24
  176. package/dist/esm/animation/shapes/outfits.js +106 -38
  177. package/dist/esm/animation/shapes/torsos.js +16 -10
  178. package/dist/esm/animation/spineExport.js +106 -120
  179. package/dist/esm/core/LocalUI.js +111 -42
  180. package/dist/esm/core/NiceBrushEngine.js +761 -551
  181. package/dist/esm/core/collaboration.js +255 -250
  182. package/dist/esm/core/colorBlindness.js +106 -114
  183. package/dist/esm/core/dragDrop.js +157 -157
  184. package/dist/esm/core/editorAsk.js +53 -40
  185. package/dist/esm/core/fixes.js +145 -170
  186. package/dist/esm/core/gridGuides.js +178 -200
  187. package/dist/esm/core/historyVisual.js +158 -134
  188. package/dist/esm/core/i18n.js +15 -13
  189. package/dist/esm/core/integrations.js +244 -248
  190. package/dist/esm/core/minimap.js +151 -150
  191. package/dist/esm/core/plugins.js +102 -112
  192. package/dist/esm/core/rtl.js +77 -82
  193. package/dist/esm/core/shortcuts.js +200 -224
  194. package/dist/esm/core/theme.js +150 -148
  195. package/dist/esm/core/yjsCollaboration.js +240 -292
  196. package/dist/esm/design/design-tools.js +13 -21
  197. package/dist/esm/font/NiceFontEditor.js +880 -315
  198. package/dist/esm/font/fontFormatUtils.js +394 -447
  199. package/dist/esm/game/GameAsset2dEditor.js +1202 -391
  200. package/dist/esm/game/GameAsset2dEditor.module.css.js +146 -3
  201. package/dist/esm/game/gameAssetTypes.js +8 -15
  202. package/dist/esm/game/gameAssetUtils.js +408 -412
  203. package/dist/esm/game/useGameAssetEditor.js +821 -762
  204. package/dist/esm/index.js +332 -69
  205. package/dist/esm/nice2dev-ui-graphics.css +1 -1
  206. package/dist/esm/node_modules/lib0/array.js +15 -69
  207. package/dist/esm/node_modules/lib0/binary.js +14 -19
  208. package/dist/esm/node_modules/lib0/broadcastchannel.js +27 -85
  209. package/dist/esm/node_modules/lib0/buffer.js +20 -80
  210. package/dist/esm/node_modules/lib0/conditions.js +4 -15
  211. package/dist/esm/node_modules/lib0/decoding.js +128 -286
  212. package/dist/esm/node_modules/lib0/dom.js +20 -43
  213. package/dist/esm/node_modules/lib0/encoding.js +90 -415
  214. package/dist/esm/node_modules/lib0/environment.js +33 -91
  215. package/dist/esm/node_modules/lib0/error.js +8 -28
  216. package/dist/esm/node_modules/lib0/function.js +31 -65
  217. package/dist/esm/node_modules/lib0/iterator.js +11 -32
  218. package/dist/esm/node_modules/lib0/logging.common.js +22 -21
  219. package/dist/esm/node_modules/lib0/logging.js +44 -70
  220. package/dist/esm/node_modules/lib0/map.js +21 -85
  221. package/dist/esm/node_modules/lib0/math.js +9 -31
  222. package/dist/esm/node_modules/lib0/number.js +7 -14
  223. package/dist/esm/node_modules/lib0/object.js +26 -87
  224. package/dist/esm/node_modules/lib0/observable.js +40 -77
  225. package/dist/esm/node_modules/lib0/pair.js +5 -19
  226. package/dist/esm/node_modules/lib0/prng.js +15 -76
  227. package/dist/esm/node_modules/lib0/promise.js +7 -29
  228. package/dist/esm/node_modules/lib0/random.js +10 -22
  229. package/dist/esm/node_modules/lib0/schema.js +367 -686
  230. package/dist/esm/node_modules/lib0/set.js +4 -9
  231. package/dist/esm/node_modules/lib0/storage.js +23 -54
  232. package/dist/esm/node_modules/lib0/string.js +26 -71
  233. package/dist/esm/node_modules/lib0/symbol.js +3 -11
  234. package/dist/esm/node_modules/lib0/time.js +3 -14
  235. package/dist/esm/node_modules/lib0/trait/equality.js +5 -27
  236. package/dist/esm/node_modules/lib0/url.js +5 -17
  237. package/dist/esm/node_modules/lib0/webcrypto.js +3 -4
  238. package/dist/esm/node_modules/y-protocols/auth.js +7 -18
  239. package/dist/esm/node_modules/y-protocols/awareness.js +58 -115
  240. package/dist/esm/node_modules/y-protocols/sync.js +26 -102
  241. package/dist/esm/node_modules/y-websocket/src/y-websocket.js +82 -218
  242. package/dist/esm/node_modules/yjs/dist/yjs.js +2263 -4899
  243. package/dist/esm/photo/FilterThumb.js +37 -23
  244. package/dist/esm/photo/NiceAITools.js +685 -466
  245. package/dist/esm/photo/PhotoEditor.js +34 -18
  246. package/dist/esm/photo/PhotoEditor.module.css.js +296 -3
  247. package/dist/esm/photo/PhotoEditorCanvas.js +250 -89
  248. package/dist/esm/photo/PhotoEditorLeftPanel.js +1086 -222
  249. package/dist/esm/photo/PhotoEditorToolbar.js +135 -17
  250. package/dist/esm/photo/photoEditorActions.js +93 -71
  251. package/dist/esm/photo/photoEditorTypes.js +32 -31
  252. package/dist/esm/photo/photoFilters.js +967 -984
  253. package/dist/esm/photo/photoOverlays.js +913 -944
  254. package/dist/esm/photo/photoSelection.js +438 -498
  255. package/dist/esm/photo/usePhotoEditor.js +740 -740
  256. package/dist/esm/pixel/HSVPicker.js +192 -174
  257. package/dist/esm/pixel/PixelEditor.js +160 -47
  258. package/dist/esm/pixel/PixelEditor.module.css.js +209 -3
  259. package/dist/esm/pixel/PixelEditorCanvas.js +29 -14
  260. package/dist/esm/pixel/PixelEditorMenuBar.js +160 -160
  261. package/dist/esm/pixel/PixelEditorRightPanel.js +377 -43
  262. package/dist/esm/pixel/PixelEditorStatusBar.js +47 -18
  263. package/dist/esm/pixel/PixelEditorTimeline.js +106 -21
  264. package/dist/esm/pixel/PixelEditorToolbar.js +99 -19
  265. package/dist/esm/pixel/SpriteGeneratorPanel.js +483 -301
  266. package/dist/esm/pixel/animalGeneratorPresets.js +782 -600
  267. package/dist/esm/pixel/asepriteFormat.js +517 -559
  268. package/dist/esm/pixel/buildingGeneratorPresets.js +699 -519
  269. package/dist/esm/pixel/characterGeneratorPresets.js +650 -543
  270. package/dist/esm/pixel/pixel-pro.js +53 -62
  271. package/dist/esm/pixel/pixelEditorExports.js +397 -427
  272. package/dist/esm/pixel/pixelEditorTypes.js +103 -107
  273. package/dist/esm/pixel/pixelEditorUtils.js +551 -560
  274. package/dist/esm/pixel/spriteGeneratorCore.js +223 -256
  275. package/dist/esm/pixel/usePixelEditor.js +1322 -1342
  276. package/dist/esm/texture/Nice3DTexturePainter.js +709 -439
  277. package/dist/esm/ui/NiceUIDesigner.js +957 -526
  278. package/dist/esm/vector/NiceSvgToCode.js +589 -445
  279. package/dist/esm/vector/VectorEditor.js +291 -116
  280. package/dist/esm/vector/VectorEditor.module.css.js +86 -3
  281. package/dist/esm/vector/VectorEditorMenuBar.js +333 -273
  282. package/dist/esm/vector/VectorEditorRightPanel.js +1094 -369
  283. package/dist/esm/vector/VectorEditorShapeRenderer.js +199 -59
  284. package/dist/esm/vector/VectorEditorStatusBar.js +39 -11
  285. package/dist/esm/vector/useVectorEditor.js +849 -888
  286. package/dist/esm/vector/vectorAnimation.js +115 -136
  287. package/dist/esm/vector/vectorBooleanOps.js +401 -484
  288. package/dist/esm/vector/vectorEditorExport.js +207 -202
  289. package/dist/esm/vector/vectorEditorImport.js +174 -188
  290. package/dist/esm/vector/vectorEditorTypes.js +50 -48
  291. package/dist/esm/vector/vectorGradients.js +158 -173
  292. package/dist/esm/vector/vectorIconExport.js +53 -58
  293. package/dist/esm/vector/vectorIconImport.js +171 -218
  294. package/package.json +9 -15
@@ -1,473 +1,420 @@
1
- /**
2
- * fontFormatUtils — OTF/TTF binary generation and OpenType feature support
3
- *
4
- * Features:
5
- * - Generate TrueType-compatible binary font data (minimal .ttf)
6
- * - OpenType feature definitions (liga, kern, smcp, onum, salt, ss01-ss20)
7
- * - Kerning table generation from pairs
8
- * - WOFF/WOFF2 wrapper
9
- * - Font file download utility
10
- */
11
- /* ── OpenType Feature Presets ── */
12
1
  const OPENTYPE_FEATURE_PRESETS = {
13
- basic: [
14
- { tag: 'kern', enabled: true, kerning: [] },
15
- {
16
- tag: 'liga',
17
- enabled: true,
18
- ligatures: [
19
- { input: ['f', 'i'], replacement: '\uFB01' },
20
- { input: ['f', 'l'], replacement: '\uFB02' },
21
- { input: ['f', 'f'], replacement: '\uFB00' },
22
- ],
23
- },
24
- ],
25
- typographic: [
26
- { tag: 'kern', enabled: true, kerning: [] },
27
- { tag: 'liga', enabled: true, ligatures: [] },
28
- { tag: 'onum', enabled: true },
29
- { tag: 'smcp', enabled: true },
30
- { tag: 'frac', enabled: true },
31
- { tag: 'zero', enabled: true },
32
- ],
33
- 'stylistic-full': [
34
- { tag: 'kern', enabled: true, kerning: [] },
35
- { tag: 'liga', enabled: true, ligatures: [] },
36
- { tag: 'salt', enabled: true },
37
- { tag: 'calt', enabled: true },
38
- { tag: 'swsh', enabled: true },
39
- { tag: 'ss01', enabled: true },
40
- { tag: 'ss02', enabled: true },
41
- { tag: 'ss03', enabled: true },
42
- ],
2
+ basic: [
3
+ { tag: "kern", enabled: true, kerning: [] },
4
+ {
5
+ tag: "liga",
6
+ enabled: true,
7
+ ligatures: [
8
+ { input: ["f", "i"], replacement: "fi" },
9
+ { input: ["f", "l"], replacement: "fl" },
10
+ { input: ["f", "f"], replacement: "ff" }
11
+ ]
12
+ }
13
+ ],
14
+ typographic: [
15
+ { tag: "kern", enabled: true, kerning: [] },
16
+ { tag: "liga", enabled: true, ligatures: [] },
17
+ { tag: "onum", enabled: true },
18
+ { tag: "smcp", enabled: true },
19
+ { tag: "frac", enabled: true },
20
+ { tag: "zero", enabled: true }
21
+ ],
22
+ "stylistic-full": [
23
+ { tag: "kern", enabled: true, kerning: [] },
24
+ { tag: "liga", enabled: true, ligatures: [] },
25
+ { tag: "salt", enabled: true },
26
+ { tag: "calt", enabled: true },
27
+ { tag: "swsh", enabled: true },
28
+ { tag: "ss01", enabled: true },
29
+ { tag: "ss02", enabled: true },
30
+ { tag: "ss03", enabled: true }
31
+ ]
43
32
  };
44
- /* ── Common Kerning Pairs ── */
45
33
  const COMMON_KERNING_PAIRS = [
46
- { left: 'A', right: 'V', value: -80 },
47
- { left: 'A', right: 'W', value: -60 },
48
- { left: 'A', right: 'Y', value: -80 },
49
- { left: 'A', right: 'T', value: -60 },
50
- { left: 'T', right: 'a', value: -60 },
51
- { left: 'T', right: 'e', value: -60 },
52
- { left: 'T', right: 'o', value: -60 },
53
- { left: 'V', right: 'a', value: -60 },
54
- { left: 'V', right: 'e', value: -50 },
55
- { left: 'V', right: 'o', value: -50 },
56
- { left: 'W', right: 'a', value: -40 },
57
- { left: 'W', right: 'e', value: -30 },
58
- { left: 'Y', right: 'a', value: -70 },
59
- { left: 'Y', right: 'e', value: -60 },
60
- { left: 'Y', right: 'o', value: -60 },
61
- { left: 'L', right: 'T', value: -50 },
62
- { left: 'L', right: 'V', value: -40 },
63
- { left: 'L', right: 'W', value: -30 },
64
- { left: 'L', right: 'Y', value: -50 },
65
- { left: 'P', right: 'a', value: -30 },
66
- { left: 'P', right: '.', value: -80 },
67
- { left: 'P', right: ',', value: -80 },
68
- { left: 'r', right: '.', value: -40 },
69
- { left: 'r', right: ',', value: -40 },
70
- { left: 'f', right: '.', value: -30 },
71
- { left: 'f', right: ',', value: -30 },
34
+ { left: "A", right: "V", value: -80 },
35
+ { left: "A", right: "W", value: -60 },
36
+ { left: "A", right: "Y", value: -80 },
37
+ { left: "A", right: "T", value: -60 },
38
+ { left: "T", right: "a", value: -60 },
39
+ { left: "T", right: "e", value: -60 },
40
+ { left: "T", right: "o", value: -60 },
41
+ { left: "V", right: "a", value: -60 },
42
+ { left: "V", right: "e", value: -50 },
43
+ { left: "V", right: "o", value: -50 },
44
+ { left: "W", right: "a", value: -40 },
45
+ { left: "W", right: "e", value: -30 },
46
+ { left: "Y", right: "a", value: -70 },
47
+ { left: "Y", right: "e", value: -60 },
48
+ { left: "Y", right: "o", value: -60 },
49
+ { left: "L", right: "T", value: -50 },
50
+ { left: "L", right: "V", value: -40 },
51
+ { left: "L", right: "W", value: -30 },
52
+ { left: "L", right: "Y", value: -50 },
53
+ { left: "P", right: "a", value: -30 },
54
+ { left: "P", right: ".", value: -80 },
55
+ { left: "P", right: ",", value: -80 },
56
+ { left: "r", right: ".", value: -40 },
57
+ { left: "r", right: ",", value: -40 },
58
+ { left: "f", right: ".", value: -30 },
59
+ { left: "f", right: ",", value: -30 }
72
60
  ];
73
- /* ── TrueType Binary Writer ── */
74
61
  class BinaryWriter {
75
- constructor() {
76
- this.chunks = [];
77
- this.size = 0;
78
- }
79
- writeUint8(v) {
80
- this.chunks.push(new Uint8Array([v & 0xff]));
81
- this.size += 1;
82
- }
83
- writeUint16(v) {
84
- const buf = new Uint8Array(2);
85
- buf[0] = (v >> 8) & 0xff;
86
- buf[1] = v & 0xff;
87
- this.chunks.push(buf);
88
- this.size += 2;
89
- }
90
- writeInt16(v) {
91
- this.writeUint16(v < 0 ? v + 0x10000 : v);
92
- }
93
- writeUint32(v) {
94
- const buf = new Uint8Array(4);
95
- buf[0] = (v >> 24) & 0xff;
96
- buf[1] = (v >> 16) & 0xff;
97
- buf[2] = (v >> 8) & 0xff;
98
- buf[3] = v & 0xff;
99
- this.chunks.push(buf);
100
- this.size += 4;
101
- }
102
- writeInt32(v) {
103
- this.writeUint32(v < 0 ? v + 0x100000000 : v);
104
- }
105
- writeFixed(v) {
106
- this.writeInt32(Math.round(v * 0x10000));
107
- }
108
- writeString(s, len) {
109
- const l = len !== null && len !== void 0 ? len : s.length;
110
- const buf = new Uint8Array(l);
111
- for (let i = 0; i < l; i++) {
112
- buf[i] = i < s.length ? s.charCodeAt(i) : 0;
113
- }
114
- this.chunks.push(buf);
115
- this.size += l;
116
- }
117
- writeBytes(data) {
118
- this.chunks.push(data);
119
- this.size += data.length;
120
- }
121
- padTo4() {
122
- const pad = (4 - (this.size % 4)) % 4;
123
- if (pad > 0) {
124
- this.writeBytes(new Uint8Array(pad));
125
- }
62
+ constructor() {
63
+ this.chunks = [];
64
+ this.size = 0;
65
+ }
66
+ writeUint8(v) {
67
+ this.chunks.push(new Uint8Array([v & 255]));
68
+ this.size += 1;
69
+ }
70
+ writeUint16(v) {
71
+ const buf = new Uint8Array(2);
72
+ buf[0] = v >> 8 & 255;
73
+ buf[1] = v & 255;
74
+ this.chunks.push(buf);
75
+ this.size += 2;
76
+ }
77
+ writeInt16(v) {
78
+ this.writeUint16(v < 0 ? v + 65536 : v);
79
+ }
80
+ writeUint32(v) {
81
+ const buf = new Uint8Array(4);
82
+ buf[0] = v >> 24 & 255;
83
+ buf[1] = v >> 16 & 255;
84
+ buf[2] = v >> 8 & 255;
85
+ buf[3] = v & 255;
86
+ this.chunks.push(buf);
87
+ this.size += 4;
88
+ }
89
+ writeInt32(v) {
90
+ this.writeUint32(v < 0 ? v + 4294967296 : v);
91
+ }
92
+ writeFixed(v) {
93
+ this.writeInt32(Math.round(v * 65536));
94
+ }
95
+ writeString(s, len) {
96
+ const l = len ?? s.length;
97
+ const buf = new Uint8Array(l);
98
+ for (let i = 0; i < l; i++) {
99
+ buf[i] = i < s.length ? s.charCodeAt(i) : 0;
126
100
  }
127
- getSize() {
128
- return this.size;
101
+ this.chunks.push(buf);
102
+ this.size += l;
103
+ }
104
+ writeBytes(data) {
105
+ this.chunks.push(data);
106
+ this.size += data.length;
107
+ }
108
+ padTo4() {
109
+ const pad = (4 - this.size % 4) % 4;
110
+ if (pad > 0) {
111
+ this.writeBytes(new Uint8Array(pad));
129
112
  }
130
- toArrayBuffer() {
131
- const result = new Uint8Array(this.size);
132
- let offset = 0;
133
- for (const chunk of this.chunks) {
134
- result.set(chunk, offset);
135
- offset += chunk.length;
136
- }
137
- return result.buffer;
113
+ }
114
+ getSize() {
115
+ return this.size;
116
+ }
117
+ toArrayBuffer() {
118
+ const result = new Uint8Array(this.size);
119
+ let offset = 0;
120
+ for (const chunk of this.chunks) {
121
+ result.set(chunk, offset);
122
+ offset += chunk.length;
138
123
  }
124
+ return result.buffer;
125
+ }
139
126
  }
140
127
  function tag(s) {
141
- return ((s.charCodeAt(0) << 24) | (s.charCodeAt(1) << 16) | (s.charCodeAt(2) << 8) | s.charCodeAt(3));
128
+ return s.charCodeAt(0) << 24 | s.charCodeAt(1) << 16 | s.charCodeAt(2) << 8 | s.charCodeAt(3);
142
129
  }
143
- /**
144
- * Build minimal TrueType font binary.
145
- * Encodes glyphs as simple contour paths from SVG path data.
146
- */
147
130
  function buildTTF(fontData, _config) {
148
- const { metrics, glyphs, name } = fontData;
149
- const w = new BinaryWriter();
150
- // Simple glyph conversion: parse SVG path → contour points
151
- // For a production font, this would use a proper path parser.
152
- // Offset Table
153
- const numTables = 9; // head, hhea, maxp, OS/2, name, cmap, glyf, loca, post
154
- w.writeUint32(0x00010000); // sfVersion (TrueType)
155
- w.writeUint16(numTables);
156
- // searchRange, entrySelector, rangeShift
157
- const sr = Math.pow(2, Math.floor(Math.log2(numTables))) * 16;
158
- w.writeUint16(sr);
159
- w.writeUint16(Math.floor(Math.log2(numTables)));
160
- w.writeUint16(numTables * 16 - sr);
161
- // Table directory placeholder — we'll calculate real offsets after building tables
162
- w.getSize();
163
- const tableNames = ['cmap', 'glyf', 'head', 'hhea', 'loca', 'maxp', 'name', 'OS/2', 'post'];
164
- // Write placeholder entries (tag, checksum, offset, length)
165
- for (let i = 0; i < numTables; i++) {
166
- w.writeUint32(tag(tableNames[i]));
167
- w.writeUint32(0); // checksum placeholder
168
- w.writeUint32(0); // offset placeholder
169
- w.writeUint32(0); // length placeholder
170
- }
171
- // For simplicity, write each table sequentially and record offsets
172
- const tableData = new Map();
173
- // head table
174
- const headStart = w.getSize();
175
- w.writeFixed(1.0); // majorVersion.minorVersion
176
- w.writeFixed(1.0); // fontRevision
177
- w.writeUint32(0); // checksumAdjustment
178
- w.writeUint32(0x5f0f3cf5); // magicNumber
179
- w.writeUint16(0x000b); // flags
180
- w.writeUint16(metrics.unitsPerEm);
181
- // created / modified (int64 — 8 bytes each)
182
- w.writeUint32(0);
131
+ const { metrics, glyphs, name } = fontData;
132
+ const w = new BinaryWriter();
133
+ const numTables = 9;
134
+ w.writeUint32(65536);
135
+ w.writeUint16(numTables);
136
+ const sr = Math.pow(2, Math.floor(Math.log2(numTables))) * 16;
137
+ w.writeUint16(sr);
138
+ w.writeUint16(Math.floor(Math.log2(numTables)));
139
+ w.writeUint16(numTables * 16 - sr);
140
+ w.getSize();
141
+ const tableNames = ["cmap", "glyf", "head", "hhea", "loca", "maxp", "name", "OS/2", "post"];
142
+ for (let i = 0; i < numTables; i++) {
143
+ w.writeUint32(tag(tableNames[i]));
183
144
  w.writeUint32(0);
184
145
  w.writeUint32(0);
185
146
  w.writeUint32(0);
186
- // xMin, yMin, xMax, yMax
187
- w.writeInt16(0);
188
- w.writeInt16(metrics.descent);
189
- w.writeInt16(metrics.unitsPerEm);
190
- w.writeInt16(metrics.ascent);
191
- w.writeUint16(0); // macStyle
192
- w.writeUint16(8); // lowestRecPPEM
193
- w.writeInt16(2); // fontDirectionHint
194
- w.writeInt16(1); // indexToLocFormat (long)
195
- w.writeInt16(0); // glyphDataFormat
196
- w.padTo4();
197
- tableData.set('head', { offset: headStart, length: w.getSize() - headStart });
198
- // hhea table
199
- const hheaStart = w.getSize();
200
- w.writeFixed(1.0);
201
- w.writeInt16(metrics.ascent);
202
- w.writeInt16(metrics.descent);
203
- w.writeInt16(metrics.lineGap);
204
- w.writeUint16(metrics.unitsPerEm); // advanceWidthMax
205
- w.writeInt16(0); // minLeftSideBearing
206
- w.writeInt16(0); // minRightSideBearing
207
- w.writeInt16(metrics.unitsPerEm); // xMaxExtent
208
- w.writeInt16(1); // caretSlopeRise
209
- w.writeInt16(0); // caretSlopeRun
210
- w.writeInt16(0); // caretOffset
211
- w.writeInt16(0);
212
- w.writeInt16(0);
213
- w.writeInt16(0);
214
- w.writeInt16(0); // reserved
215
- w.writeInt16(0); // metricDataFormat
216
- w.writeUint16(glyphs.length + 1); // numberOfHMetrics
217
- w.padTo4();
218
- tableData.set('hhea', { offset: hheaStart, length: w.getSize() - hheaStart });
219
- // maxp table
220
- const maxpStart = w.getSize();
221
- w.writeFixed(1.0);
222
- w.writeUint16(glyphs.length + 1); // numGlyphs (.notdef + glyphs)
223
- w.writeUint16(0); // maxPoints
224
- w.writeUint16(0); // maxContours
225
- w.writeUint16(0); // maxCompositePoints
226
- w.writeUint16(0); // maxCompositeContours
227
- w.writeUint16(1); // maxZones
228
- w.writeUint16(0); // maxTwilightPoints
229
- w.writeUint16(0); // maxStorage
230
- w.writeUint16(0); // maxFunctionDefs
231
- w.writeUint16(0); // maxInstructionDefs
232
- w.writeUint16(0); // maxStackElements
233
- w.writeUint16(0); // maxSizeOfInstructions
234
- w.writeUint16(0); // maxComponentElements
235
- w.writeUint16(0); // maxComponentDepth
236
- w.padTo4();
237
- tableData.set('maxp', { offset: maxpStart, length: w.getSize() - maxpStart });
238
- // OS/2 table (minimal)
239
- const os2Start = w.getSize();
240
- w.writeUint16(4); // version
241
- w.writeInt16(500); // xAvgCharWidth
242
- w.writeUint16(400); // usWeightClass (Regular)
243
- w.writeUint16(5); // usWidthClass (Medium)
244
- w.writeUint16(0); // fsType
245
- w.writeInt16(Math.round(metrics.unitsPerEm * 0.6)); // subscript sizes + offsets (10 int16)
246
- w.writeInt16(Math.round(metrics.unitsPerEm * 0.6));
247
- w.writeInt16(0);
248
- w.writeInt16(Math.round(metrics.unitsPerEm * 0.1));
249
- w.writeInt16(Math.round(metrics.unitsPerEm * 0.6));
250
- w.writeInt16(Math.round(metrics.unitsPerEm * 0.6));
251
- w.writeInt16(0);
252
- w.writeInt16(Math.round(metrics.unitsPerEm * 0.4));
253
- w.writeInt16(0); // yStrikeoutSize
254
- w.writeInt16(Math.round(metrics.xHeight * 0.6)); // yStrikeoutPosition
255
- w.writeInt16(0); // sFamilyClass
256
- // PANOSE (10 bytes)
257
- for (let i = 0; i < 10; i++) {
258
- w.writeUint8(0);
259
- }
260
- // Unicode ranges (16 bytes)
261
- w.writeUint32(0x00000001); // Basic Latin
262
- w.writeUint32(0);
263
- w.writeUint32(0);
264
- w.writeUint32(0);
265
- w.writeString(' ', 4); // achVendID
266
- w.writeUint16(0x0040); // fsSelection (Regular)
267
- w.writeUint16(0x0020); // usFirstCharIndex (space)
268
- w.writeUint16(0x007e); // usLastCharIndex (~)
269
- w.writeInt16(metrics.ascent); // sTypoAscender
270
- w.writeInt16(metrics.descent); // sTypoDescender
271
- w.writeInt16(metrics.lineGap); // sTypoLineGap
272
- w.writeUint16(metrics.ascent); // usWinAscent
273
- w.writeUint16(Math.abs(metrics.descent)); // usWinDescent
274
- w.writeUint32(0x00000001); // ulCodePageRange1
275
- w.writeUint32(0); // ulCodePageRange2
276
- w.writeInt16(metrics.xHeight); // sxHeight
277
- w.writeInt16(metrics.capHeight); // sCapHeight
278
- w.writeUint16(0); // usDefaultChar
279
- w.writeUint16(0x0020); // usBreakChar
280
- w.writeUint16(1); // usMaxContext
281
- w.padTo4();
282
- tableData.set('OS/2', { offset: os2Start, length: w.getSize() - os2Start });
283
- // name table
284
- const nameStart = w.getSize();
285
- const nameStrings = [
286
- { nameID: 0, str: `Copyright 2024 ${name}` },
287
- { nameID: 1, str: fontData.family },
288
- { nameID: 2, str: 'Regular' },
289
- { nameID: 3, str: `${name}-Regular` },
290
- { nameID: 4, str: `${name} Regular` },
291
- { nameID: 5, str: 'Version 1.0' },
292
- { nameID: 6, str: `${name}-Regular` },
293
- ];
294
- w.writeUint16(0); // format
295
- w.writeUint16(nameStrings.length); // count
296
- const nameStorageOffset = 6 + nameStrings.length * 12;
297
- w.writeUint16(nameStorageOffset); // stringOffset
298
- let strOffset = 0;
299
- for (const ns of nameStrings) {
300
- w.writeUint16(1); // platformID (Macintosh)
301
- w.writeUint16(0); // encodingID
302
- w.writeUint16(0); // languageID
303
- w.writeUint16(ns.nameID);
304
- w.writeUint16(ns.str.length); // length
305
- w.writeUint16(strOffset); // offset
306
- strOffset += ns.str.length;
307
- }
308
- for (const ns of nameStrings) {
309
- w.writeString(ns.str);
310
- }
311
- w.padTo4();
312
- tableData.set('name', { offset: nameStart, length: w.getSize() - nameStart });
313
- // cmap table (format 4)
314
- const cmapStart = w.getSize();
315
- w.writeUint16(0); // version
316
- w.writeUint16(1); // numTables
317
- w.writeUint16(3); // platformID (Windows)
318
- w.writeUint16(1); // encodingID (BMP)
319
- w.writeUint32(12); // offset to subtable
320
- // Format 4 subtable
321
- const sortedGlyphs = [...glyphs].sort((a, b) => a.unicode - b.unicode);
322
- const segCount = sortedGlyphs.length + 1; // + end segment
323
- const fmt4Size = 14 + segCount * 8;
324
- w.writeUint16(4); // format
325
- w.writeUint16(fmt4Size); // length
326
- w.writeUint16(0); // language
327
- w.writeUint16(segCount * 2); // segCountX2
328
- const searchRange2 = Math.pow(2, Math.floor(Math.log2(segCount))) * 2;
329
- w.writeUint16(searchRange2);
330
- w.writeUint16(Math.floor(Math.log2(segCount)));
331
- w.writeUint16(segCount * 2 - searchRange2);
332
- // endCode
333
- for (const g of sortedGlyphs) {
334
- w.writeUint16(g.unicode);
335
- }
336
- w.writeUint16(0xffff);
337
- w.writeUint16(0); // reservedPad
338
- // startCode
339
- for (const g of sortedGlyphs) {
340
- w.writeUint16(g.unicode);
341
- }
342
- w.writeUint16(0xffff);
343
- // idDelta (glyph index = unicode + delta)
344
- for (let i = 0; i < sortedGlyphs.length; i++) {
345
- const delta = i + 1 - sortedGlyphs[i].unicode;
346
- w.writeInt16(delta);
347
- }
348
- w.writeInt16(1);
349
- // idRangeOffset (all zero — use delta)
350
- for (let i = 0; i <= sortedGlyphs.length; i++) {
351
- w.writeUint16(0);
352
- }
353
- w.padTo4();
354
- tableData.set('cmap', { offset: cmapStart, length: w.getSize() - cmapStart });
355
- // glyf table (empty glyphs — just placeholder records)
356
- const glyfStart = w.getSize();
357
- const glyphOffsets = [0]; // .notdef at offset 0
358
- // .notdef: empty glyph
359
- w.writeInt16(0); // numberOfContours
147
+ }
148
+ const tableData = /* @__PURE__ */ new Map();
149
+ const headStart = w.getSize();
150
+ w.writeFixed(1);
151
+ w.writeFixed(1);
152
+ w.writeUint32(0);
153
+ w.writeUint32(1594834165);
154
+ w.writeUint16(11);
155
+ w.writeUint16(metrics.unitsPerEm);
156
+ w.writeUint32(0);
157
+ w.writeUint32(0);
158
+ w.writeUint32(0);
159
+ w.writeUint32(0);
160
+ w.writeInt16(0);
161
+ w.writeInt16(metrics.descent);
162
+ w.writeInt16(metrics.unitsPerEm);
163
+ w.writeInt16(metrics.ascent);
164
+ w.writeUint16(0);
165
+ w.writeUint16(8);
166
+ w.writeInt16(2);
167
+ w.writeInt16(1);
168
+ w.writeInt16(0);
169
+ w.padTo4();
170
+ tableData.set("head", { offset: headStart, length: w.getSize() - headStart });
171
+ const hheaStart = w.getSize();
172
+ w.writeFixed(1);
173
+ w.writeInt16(metrics.ascent);
174
+ w.writeInt16(metrics.descent);
175
+ w.writeInt16(metrics.lineGap);
176
+ w.writeUint16(metrics.unitsPerEm);
177
+ w.writeInt16(0);
178
+ w.writeInt16(0);
179
+ w.writeInt16(metrics.unitsPerEm);
180
+ w.writeInt16(1);
181
+ w.writeInt16(0);
182
+ w.writeInt16(0);
183
+ w.writeInt16(0);
184
+ w.writeInt16(0);
185
+ w.writeInt16(0);
186
+ w.writeInt16(0);
187
+ w.writeInt16(0);
188
+ w.writeUint16(glyphs.length + 1);
189
+ w.padTo4();
190
+ tableData.set("hhea", { offset: hheaStart, length: w.getSize() - hheaStart });
191
+ const maxpStart = w.getSize();
192
+ w.writeFixed(1);
193
+ w.writeUint16(glyphs.length + 1);
194
+ w.writeUint16(0);
195
+ w.writeUint16(0);
196
+ w.writeUint16(0);
197
+ w.writeUint16(0);
198
+ w.writeUint16(1);
199
+ w.writeUint16(0);
200
+ w.writeUint16(0);
201
+ w.writeUint16(0);
202
+ w.writeUint16(0);
203
+ w.writeUint16(0);
204
+ w.writeUint16(0);
205
+ w.writeUint16(0);
206
+ w.writeUint16(0);
207
+ w.padTo4();
208
+ tableData.set("maxp", { offset: maxpStart, length: w.getSize() - maxpStart });
209
+ const os2Start = w.getSize();
210
+ w.writeUint16(4);
211
+ w.writeInt16(500);
212
+ w.writeUint16(400);
213
+ w.writeUint16(5);
214
+ w.writeUint16(0);
215
+ w.writeInt16(Math.round(metrics.unitsPerEm * 0.6));
216
+ w.writeInt16(Math.round(metrics.unitsPerEm * 0.6));
217
+ w.writeInt16(0);
218
+ w.writeInt16(Math.round(metrics.unitsPerEm * 0.1));
219
+ w.writeInt16(Math.round(metrics.unitsPerEm * 0.6));
220
+ w.writeInt16(Math.round(metrics.unitsPerEm * 0.6));
221
+ w.writeInt16(0);
222
+ w.writeInt16(Math.round(metrics.unitsPerEm * 0.4));
223
+ w.writeInt16(0);
224
+ w.writeInt16(Math.round(metrics.xHeight * 0.6));
225
+ w.writeInt16(0);
226
+ for (let i = 0; i < 10; i++) {
227
+ w.writeUint8(0);
228
+ }
229
+ w.writeUint32(1);
230
+ w.writeUint32(0);
231
+ w.writeUint32(0);
232
+ w.writeUint32(0);
233
+ w.writeString(" ", 4);
234
+ w.writeUint16(64);
235
+ w.writeUint16(32);
236
+ w.writeUint16(126);
237
+ w.writeInt16(metrics.ascent);
238
+ w.writeInt16(metrics.descent);
239
+ w.writeInt16(metrics.lineGap);
240
+ w.writeUint16(metrics.ascent);
241
+ w.writeUint16(Math.abs(metrics.descent));
242
+ w.writeUint32(1);
243
+ w.writeUint32(0);
244
+ w.writeInt16(metrics.xHeight);
245
+ w.writeInt16(metrics.capHeight);
246
+ w.writeUint16(0);
247
+ w.writeUint16(32);
248
+ w.writeUint16(1);
249
+ w.padTo4();
250
+ tableData.set("OS/2", { offset: os2Start, length: w.getSize() - os2Start });
251
+ const nameStart = w.getSize();
252
+ const nameStrings = [
253
+ { nameID: 0, str: `Copyright 2024 ${name}` },
254
+ { nameID: 1, str: fontData.family },
255
+ { nameID: 2, str: "Regular" },
256
+ { nameID: 3, str: `${name}-Regular` },
257
+ { nameID: 4, str: `${name} Regular` },
258
+ { nameID: 5, str: "Version 1.0" },
259
+ { nameID: 6, str: `${name}-Regular` }
260
+ ];
261
+ w.writeUint16(0);
262
+ w.writeUint16(nameStrings.length);
263
+ const nameStorageOffset = 6 + nameStrings.length * 12;
264
+ w.writeUint16(nameStorageOffset);
265
+ let strOffset = 0;
266
+ for (const ns of nameStrings) {
267
+ w.writeUint16(1);
268
+ w.writeUint16(0);
269
+ w.writeUint16(0);
270
+ w.writeUint16(ns.nameID);
271
+ w.writeUint16(ns.str.length);
272
+ w.writeUint16(strOffset);
273
+ strOffset += ns.str.length;
274
+ }
275
+ for (const ns of nameStrings) {
276
+ w.writeString(ns.str);
277
+ }
278
+ w.padTo4();
279
+ tableData.set("name", { offset: nameStart, length: w.getSize() - nameStart });
280
+ const cmapStart = w.getSize();
281
+ w.writeUint16(0);
282
+ w.writeUint16(1);
283
+ w.writeUint16(3);
284
+ w.writeUint16(1);
285
+ w.writeUint32(12);
286
+ const sortedGlyphs = [...glyphs].sort((a, b) => a.unicode - b.unicode);
287
+ const segCount = sortedGlyphs.length + 1;
288
+ const fmt4Size = 14 + segCount * 8;
289
+ w.writeUint16(4);
290
+ w.writeUint16(fmt4Size);
291
+ w.writeUint16(0);
292
+ w.writeUint16(segCount * 2);
293
+ const searchRange2 = Math.pow(2, Math.floor(Math.log2(segCount))) * 2;
294
+ w.writeUint16(searchRange2);
295
+ w.writeUint16(Math.floor(Math.log2(segCount)));
296
+ w.writeUint16(segCount * 2 - searchRange2);
297
+ for (const g of sortedGlyphs) {
298
+ w.writeUint16(g.unicode);
299
+ }
300
+ w.writeUint16(65535);
301
+ w.writeUint16(0);
302
+ for (const g of sortedGlyphs) {
303
+ w.writeUint16(g.unicode);
304
+ }
305
+ w.writeUint16(65535);
306
+ for (let i = 0; i < sortedGlyphs.length; i++) {
307
+ const delta = i + 1 - sortedGlyphs[i].unicode;
308
+ w.writeInt16(delta);
309
+ }
310
+ w.writeInt16(1);
311
+ for (let i = 0; i <= sortedGlyphs.length; i++) {
312
+ w.writeUint16(0);
313
+ }
314
+ w.padTo4();
315
+ tableData.set("cmap", { offset: cmapStart, length: w.getSize() - cmapStart });
316
+ const glyfStart = w.getSize();
317
+ const glyphOffsets = [0];
318
+ w.writeInt16(0);
319
+ w.writeInt16(0);
320
+ w.writeInt16(0);
321
+ w.writeInt16(0);
322
+ w.writeInt16(0);
323
+ for (let i = 0; i < glyphs.length; i++) {
324
+ glyphOffsets.push(w.getSize() - glyfStart);
360
325
  w.writeInt16(0);
361
326
  w.writeInt16(0);
362
327
  w.writeInt16(0);
363
- w.writeInt16(0); // bbox
364
- for (let i = 0; i < glyphs.length; i++) {
365
- glyphOffsets.push(w.getSize() - glyfStart);
366
- // Simple empty glyph placeholder
367
- w.writeInt16(0);
368
- w.writeInt16(0);
369
- w.writeInt16(0);
370
- w.writeInt16(Math.round(glyphs[i].advanceWidth));
371
- w.writeInt16(metrics.ascent);
372
- }
373
- glyphOffsets.push(w.getSize() - glyfStart); // end offset
374
- w.padTo4();
375
- tableData.set('glyf', { offset: glyfStart, length: w.getSize() - glyfStart });
376
- // loca table (long format)
377
- const locaStart = w.getSize();
378
- for (const off of glyphOffsets) {
379
- w.writeUint32(off);
380
- }
381
- w.padTo4();
382
- tableData.set('loca', { offset: locaStart, length: w.getSize() - locaStart });
383
- // post table
384
- const postStart = w.getSize();
385
- w.writeFixed(3.0); // version 3.0 (no glyph names)
386
- w.writeFixed(0); // italicAngle
387
- w.writeInt16(-100); // underlinePosition
388
- w.writeInt16(50); // underlineThickness
389
- w.writeUint32(0); // isFixedPitch
390
- w.writeUint32(0); // minMemType42
391
- w.writeUint32(0); // maxMemType42
392
- w.writeUint32(0); // minMemType1
393
- w.writeUint32(0); // maxMemType1
394
- w.padTo4();
395
- tableData.set('post', { offset: postStart, length: w.getSize() - postStart });
396
- return w.toArrayBuffer();
328
+ w.writeInt16(Math.round(glyphs[i].advanceWidth));
329
+ w.writeInt16(metrics.ascent);
330
+ }
331
+ glyphOffsets.push(w.getSize() - glyfStart);
332
+ w.padTo4();
333
+ tableData.set("glyf", { offset: glyfStart, length: w.getSize() - glyfStart });
334
+ const locaStart = w.getSize();
335
+ for (const off of glyphOffsets) {
336
+ w.writeUint32(off);
337
+ }
338
+ w.padTo4();
339
+ tableData.set("loca", { offset: locaStart, length: w.getSize() - locaStart });
340
+ const postStart = w.getSize();
341
+ w.writeFixed(3);
342
+ w.writeFixed(0);
343
+ w.writeInt16(-100);
344
+ w.writeInt16(50);
345
+ w.writeUint32(0);
346
+ w.writeUint32(0);
347
+ w.writeUint32(0);
348
+ w.writeUint32(0);
349
+ w.writeUint32(0);
350
+ w.padTo4();
351
+ tableData.set("post", { offset: postStart, length: w.getSize() - postStart });
352
+ return w.toArrayBuffer();
397
353
  }
398
- /**
399
- * Wrap TrueType data into WOFF format.
400
- */
401
354
  function wrapWOFF(ttfData) {
402
- const w = new BinaryWriter();
403
- const ttf = new Uint8Array(ttfData);
404
- w.writeUint32(tag('wOFF')); // signature
405
- w.writeUint32(0x00010000); // flavor (TrueType)
406
- w.writeUint32(0); // length placeholder
407
- w.writeUint16(0); // numTables placeholder
408
- w.writeUint16(0); // reserved
409
- w.writeUint32(ttf.length); // totalSfntSize
410
- w.writeUint16(1);
411
- w.writeUint16(0); // majorVersion, minorVersion
412
- w.writeUint32(0); // metaOffset
413
- w.writeUint32(0); // metaLength
414
- w.writeUint32(0); // metaOrigLength
415
- w.writeUint32(0); // privOffset
416
- w.writeUint32(0); // privLength
417
- // For simplicity, embed the entire TTF uncompressed
418
- w.writeBytes(ttf);
419
- return w.toArrayBuffer();
355
+ const w = new BinaryWriter();
356
+ const ttf = new Uint8Array(ttfData);
357
+ w.writeUint32(tag("wOFF"));
358
+ w.writeUint32(65536);
359
+ w.writeUint32(0);
360
+ w.writeUint16(0);
361
+ w.writeUint16(0);
362
+ w.writeUint32(ttf.length);
363
+ w.writeUint16(1);
364
+ w.writeUint16(0);
365
+ w.writeUint32(0);
366
+ w.writeUint32(0);
367
+ w.writeUint32(0);
368
+ w.writeUint32(0);
369
+ w.writeUint32(0);
370
+ w.writeBytes(ttf);
371
+ return w.toArrayBuffer();
420
372
  }
421
- /**
422
- * Download font file to user's device.
423
- */
424
373
  function downloadFont(fontData, format, exportToSvgFont) {
425
- let blob;
426
- let ext;
427
- if (format === 'svg' && exportToSvgFont) {
428
- const svgStr = exportToSvgFont(fontData);
429
- blob = new Blob([svgStr], { type: 'image/svg+xml' });
430
- ext = 'svg';
431
- }
432
- else if (format === 'woff') {
433
- const ttf = buildTTF(fontData);
434
- const woff = wrapWOFF(ttf);
435
- blob = new Blob([woff], { type: 'font/woff' });
436
- ext = 'woff';
437
- }
438
- else {
439
- const ttf = buildTTF(fontData);
440
- blob = new Blob([ttf], { type: 'font/ttf' });
441
- ext = 'ttf';
442
- }
443
- const url = URL.createObjectURL(blob);
444
- const link = document.createElement('a');
445
- link.download = `${fontData.name || 'font'}.${ext}`;
446
- link.href = url;
447
- link.click();
448
- URL.revokeObjectURL(url);
374
+ let blob;
375
+ let ext;
376
+ if (format === "svg" && exportToSvgFont) {
377
+ const svgStr = exportToSvgFont(fontData);
378
+ blob = new Blob([svgStr], { type: "image/svg+xml" });
379
+ ext = "svg";
380
+ } else if (format === "woff") {
381
+ const ttf = buildTTF(fontData);
382
+ const woff = wrapWOFF(ttf);
383
+ blob = new Blob([woff], { type: "font/woff" });
384
+ ext = "woff";
385
+ } else {
386
+ const ttf = buildTTF(fontData);
387
+ blob = new Blob([ttf], { type: "font/ttf" });
388
+ ext = "ttf";
389
+ }
390
+ const url = URL.createObjectURL(blob);
391
+ const link = document.createElement("a");
392
+ link.download = `${fontData.name || "font"}.${ext}`;
393
+ link.href = url;
394
+ link.click();
395
+ URL.revokeObjectURL(url);
449
396
  }
450
- /**
451
- * Auto-generate kerning pairs based on glyph shapes.
452
- * Uses heuristic: characters with diagonal strokes (A, V, W, Y) need negative kern
453
- * against round/short characters.
454
- */
455
397
  function autoKern(glyphs, metrics) {
456
- const pairs = [];
457
- const scale = metrics.unitsPerEm / 1000;
458
- // Apply common kerning pairs if glyphs exist
459
- for (const commonPair of COMMON_KERNING_PAIRS) {
460
- const leftExists = glyphs.some((g) => g.char === commonPair.left);
461
- const rightExists = glyphs.some((g) => g.char === commonPair.right);
462
- if (leftExists && rightExists) {
463
- pairs.push({
464
- left: commonPair.left,
465
- right: commonPair.right,
466
- value: Math.round(commonPair.value * scale),
467
- });
468
- }
398
+ const pairs = [];
399
+ const scale = metrics.unitsPerEm / 1e3;
400
+ for (const commonPair of COMMON_KERNING_PAIRS) {
401
+ const leftExists = glyphs.some((g) => g.char === commonPair.left);
402
+ const rightExists = glyphs.some((g) => g.char === commonPair.right);
403
+ if (leftExists && rightExists) {
404
+ pairs.push({
405
+ left: commonPair.left,
406
+ right: commonPair.right,
407
+ value: Math.round(commonPair.value * scale)
408
+ });
469
409
  }
470
- return pairs;
410
+ }
411
+ return pairs;
471
412
  }
472
-
473
- export { COMMON_KERNING_PAIRS, OPENTYPE_FEATURE_PRESETS, autoKern, buildTTF, downloadFont, wrapWOFF };
413
+ export {
414
+ COMMON_KERNING_PAIRS,
415
+ OPENTYPE_FEATURE_PRESETS,
416
+ autoKern,
417
+ buildTTF,
418
+ downloadFont,
419
+ wrapWOFF
420
+ };