react-pdf-rtl 0.1.1 → 0.1.2

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/dist/index.d.mts CHANGED
@@ -155,10 +155,13 @@ interface RegisterRTLFontOptions {
155
155
  */
156
156
  declare function registerRTLFont(options: RegisterRTLFontOptions): void;
157
157
  /**
158
- * Registers the Rubik font from Google Fonts CDN.
158
+ * Registers the Rubik font from Google Fonts GitHub repository (TTF format).
159
159
  * Rubik is the recommended font for Hebrew PDFs — designed for Hebrew,
160
160
  * supports all weights, and renders cleanly in @react-pdf/renderer.
161
161
  *
162
+ * Uses the variable TTF font (single file, all weights 300–900).
163
+ * Note: @react-pdf/renderer requires TTF/OTF — WOFF2 is not supported.
164
+ *
162
165
  * Weights registered: 300 (Light), 400 (Regular), 500 (Medium), 700 (Bold)
163
166
  */
164
167
  declare function registerRubik(): void;
package/dist/index.d.ts CHANGED
@@ -155,10 +155,13 @@ interface RegisterRTLFontOptions {
155
155
  */
156
156
  declare function registerRTLFont(options: RegisterRTLFontOptions): void;
157
157
  /**
158
- * Registers the Rubik font from Google Fonts CDN.
158
+ * Registers the Rubik font from Google Fonts GitHub repository (TTF format).
159
159
  * Rubik is the recommended font for Hebrew PDFs — designed for Hebrew,
160
160
  * supports all weights, and renders cleanly in @react-pdf/renderer.
161
161
  *
162
+ * Uses the variable TTF font (single file, all weights 300–900).
163
+ * Note: @react-pdf/renderer requires TTF/OTF — WOFF2 is not supported.
164
+ *
162
165
  * Weights registered: 300 (Light), 400 (Regular), 500 (Medium), 700 (Bold)
163
166
  */
164
167
  declare function registerRubik(): void;
package/dist/index.js CHANGED
@@ -109,7 +109,7 @@ function formatCurrencyRTL(amount, symbol = "\u20AA", locale = "he-IL") {
109
109
  maximumFractionDigits: 2
110
110
  });
111
111
  const valueStr = amount < 0 ? `-${formatted}` : formatted;
112
- return `\u200F${symbol}${wrapLTR(valueStr)}`;
112
+ return `${symbol}${valueStr}`;
113
113
  }
114
114
  function splitBidiSegments(text) {
115
115
  if (!text) return [];
@@ -141,15 +141,9 @@ function stripBidiMarkers(text) {
141
141
  var import_jsx_runtime = require("react/jsx-runtime");
142
142
  function RTLText({ children, style, direction = "auto", wrap = true, debug }) {
143
143
  const str = String(children);
144
- let content;
145
- if (direction === "rtl") {
146
- content = wrapRTL(str);
147
- } else if (direction === "ltr") {
148
- content = str;
149
- } else {
150
- content = smartWrap(str);
151
- }
152
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_renderer.Text, { style, wrap, debug, children: content });
144
+ const isRTL = direction === "rtl" || direction === "auto" && isRTLDominant(str);
145
+ const dirStyle = isRTL ? { direction: "rtl", textAlign: "right" } : {};
146
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_renderer.Text, { style: [dirStyle, style], wrap, debug, children: str });
153
147
  }
154
148
  function RTLView({ children, style, debug }) {
155
149
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_renderer.View, { style: [styles.rtlView, style], debug, children });
@@ -196,9 +190,10 @@ function RTLTable({
196
190
  fontSize,
197
191
  fontWeight: "bold",
198
192
  color: headerColor,
199
- textAlign: (_a = col.align) != null ? _a : "right"
193
+ textAlign: (_a = col.align) != null ? _a : "right",
194
+ direction: "rtl"
200
195
  },
201
- children: wrapRTL(col.header)
196
+ children: col.header
202
197
  }
203
198
  ) }, col.key);
204
199
  }) }),
@@ -219,8 +214,7 @@ function RTLTable({
219
214
  } else if (col.isCurrency && typeof raw === "number") {
220
215
  cellText = formatCurrencyRTL(raw);
221
216
  } else {
222
- const str = String(raw != null ? raw : "");
223
- cellText = hasRTLChars(str) ? wrapRTL(str) : str;
217
+ cellText = String(raw != null ? raw : "");
224
218
  }
225
219
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_renderer.View, { style: colStyles[i], children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
226
220
  import_renderer.Text,
@@ -228,7 +222,8 @@ function RTLTable({
228
222
  style: {
229
223
  fontSize,
230
224
  color: "#111827",
231
- textAlign: (_a = col.align) != null ? _a : col.isCurrency ? "left" : "right"
225
+ textAlign: (_a = col.align) != null ? _a : col.isCurrency ? "left" : "right",
226
+ direction: hasRTLChars(String(raw != null ? raw : "")) ? "rtl" : "ltr"
232
227
  },
233
228
  children: cellText
234
229
  }
@@ -262,7 +257,7 @@ function RTLSummaryRow({
262
257
  }) {
263
258
  const displayValue = isCurrency && typeof value === "number" ? formatCurrencyRTL(value) : String(value);
264
259
  return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_renderer.View, { style: [styles.summaryRow, { fontFamily }], children: [
265
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_renderer.Text, { style: { fontSize, fontWeight: bold ? "bold" : "normal", color, textAlign: "right" }, children: wrapRTL(label) }),
260
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_renderer.Text, { style: { fontSize, fontWeight: bold ? "bold" : "normal", color, textAlign: "right", direction: "rtl" }, children: label }),
266
261
  /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_renderer.Text, { style: { fontSize, fontWeight: bold ? "bold" : "normal", color, textAlign: "left" }, children: displayValue })
267
262
  ] });
268
263
  }
@@ -293,25 +288,14 @@ function registerRTLFont(options) {
293
288
  });
294
289
  }
295
290
  function registerRubik() {
291
+ const src = "https://raw.githubusercontent.com/google/fonts/main/ofl/rubik/Rubik%5Bwght%5D.ttf";
296
292
  import_renderer2.Font.register({
297
293
  family: "Rubik",
298
294
  fonts: [
299
- {
300
- src: "https://fonts.gstatic.com/s/rubik/v28/iJWZBXyIfDnIV5PNhY1KTN7Z-Yh-B4i1UA.woff2",
301
- fontWeight: 300
302
- },
303
- {
304
- src: "https://fonts.gstatic.com/s/rubik/v28/iJWZBXyIfDnIV5PNhY1KTN7Z-Yh-NYi1UA.woff2",
305
- fontWeight: 400
306
- },
307
- {
308
- src: "https://fonts.gstatic.com/s/rubik/v28/iJWZBXyIfDnIV5PNhY1KTN7Z-Yh-B4i1UA.woff2",
309
- fontWeight: 500
310
- },
311
- {
312
- src: "https://fonts.gstatic.com/s/rubik/v28/iJWZBXyIfDnIV5PNhY1KTN7Z-Yh-0oi1UA.woff2",
313
- fontWeight: 700
314
- }
295
+ { src, fontWeight: 300 },
296
+ { src, fontWeight: 400 },
297
+ { src, fontWeight: 500 },
298
+ { src, fontWeight: 700 }
315
299
  ]
316
300
  });
317
301
  }
package/dist/index.mjs CHANGED
@@ -63,7 +63,7 @@ function formatCurrencyRTL(amount, symbol = "\u20AA", locale = "he-IL") {
63
63
  maximumFractionDigits: 2
64
64
  });
65
65
  const valueStr = amount < 0 ? `-${formatted}` : formatted;
66
- return `\u200F${symbol}${wrapLTR(valueStr)}`;
66
+ return `${symbol}${valueStr}`;
67
67
  }
68
68
  function splitBidiSegments(text) {
69
69
  if (!text) return [];
@@ -95,15 +95,9 @@ function stripBidiMarkers(text) {
95
95
  import { jsx, jsxs } from "react/jsx-runtime";
96
96
  function RTLText({ children, style, direction = "auto", wrap = true, debug }) {
97
97
  const str = String(children);
98
- let content;
99
- if (direction === "rtl") {
100
- content = wrapRTL(str);
101
- } else if (direction === "ltr") {
102
- content = str;
103
- } else {
104
- content = smartWrap(str);
105
- }
106
- return /* @__PURE__ */ jsx(Text, { style, wrap, debug, children: content });
98
+ const isRTL = direction === "rtl" || direction === "auto" && isRTLDominant(str);
99
+ const dirStyle = isRTL ? { direction: "rtl", textAlign: "right" } : {};
100
+ return /* @__PURE__ */ jsx(Text, { style: [dirStyle, style], wrap, debug, children: str });
107
101
  }
108
102
  function RTLView({ children, style, debug }) {
109
103
  return /* @__PURE__ */ jsx(View, { style: [styles.rtlView, style], debug, children });
@@ -150,9 +144,10 @@ function RTLTable({
150
144
  fontSize,
151
145
  fontWeight: "bold",
152
146
  color: headerColor,
153
- textAlign: (_a = col.align) != null ? _a : "right"
147
+ textAlign: (_a = col.align) != null ? _a : "right",
148
+ direction: "rtl"
154
149
  },
155
- children: wrapRTL(col.header)
150
+ children: col.header
156
151
  }
157
152
  ) }, col.key);
158
153
  }) }),
@@ -173,8 +168,7 @@ function RTLTable({
173
168
  } else if (col.isCurrency && typeof raw === "number") {
174
169
  cellText = formatCurrencyRTL(raw);
175
170
  } else {
176
- const str = String(raw != null ? raw : "");
177
- cellText = hasRTLChars(str) ? wrapRTL(str) : str;
171
+ cellText = String(raw != null ? raw : "");
178
172
  }
179
173
  return /* @__PURE__ */ jsx(View, { style: colStyles[i], children: /* @__PURE__ */ jsx(
180
174
  Text,
@@ -182,7 +176,8 @@ function RTLTable({
182
176
  style: {
183
177
  fontSize,
184
178
  color: "#111827",
185
- textAlign: (_a = col.align) != null ? _a : col.isCurrency ? "left" : "right"
179
+ textAlign: (_a = col.align) != null ? _a : col.isCurrency ? "left" : "right",
180
+ direction: hasRTLChars(String(raw != null ? raw : "")) ? "rtl" : "ltr"
186
181
  },
187
182
  children: cellText
188
183
  }
@@ -216,7 +211,7 @@ function RTLSummaryRow({
216
211
  }) {
217
212
  const displayValue = isCurrency && typeof value === "number" ? formatCurrencyRTL(value) : String(value);
218
213
  return /* @__PURE__ */ jsxs(View, { style: [styles.summaryRow, { fontFamily }], children: [
219
- /* @__PURE__ */ jsx(Text, { style: { fontSize, fontWeight: bold ? "bold" : "normal", color, textAlign: "right" }, children: wrapRTL(label) }),
214
+ /* @__PURE__ */ jsx(Text, { style: { fontSize, fontWeight: bold ? "bold" : "normal", color, textAlign: "right", direction: "rtl" }, children: label }),
220
215
  /* @__PURE__ */ jsx(Text, { style: { fontSize, fontWeight: bold ? "bold" : "normal", color, textAlign: "left" }, children: displayValue })
221
216
  ] });
222
217
  }
@@ -247,25 +242,14 @@ function registerRTLFont(options) {
247
242
  });
248
243
  }
249
244
  function registerRubik() {
245
+ const src = "https://raw.githubusercontent.com/google/fonts/main/ofl/rubik/Rubik%5Bwght%5D.ttf";
250
246
  Font.register({
251
247
  family: "Rubik",
252
248
  fonts: [
253
- {
254
- src: "https://fonts.gstatic.com/s/rubik/v28/iJWZBXyIfDnIV5PNhY1KTN7Z-Yh-B4i1UA.woff2",
255
- fontWeight: 300
256
- },
257
- {
258
- src: "https://fonts.gstatic.com/s/rubik/v28/iJWZBXyIfDnIV5PNhY1KTN7Z-Yh-NYi1UA.woff2",
259
- fontWeight: 400
260
- },
261
- {
262
- src: "https://fonts.gstatic.com/s/rubik/v28/iJWZBXyIfDnIV5PNhY1KTN7Z-Yh-B4i1UA.woff2",
263
- fontWeight: 500
264
- },
265
- {
266
- src: "https://fonts.gstatic.com/s/rubik/v28/iJWZBXyIfDnIV5PNhY1KTN7Z-Yh-0oi1UA.woff2",
267
- fontWeight: 700
268
- }
249
+ { src, fontWeight: 300 },
250
+ { src, fontWeight: 400 },
251
+ { src, fontWeight: 500 },
252
+ { src, fontWeight: 700 }
269
253
  ]
270
254
  });
271
255
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-pdf-rtl",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "RTL (Hebrew & Arabic) support utilities and components for @react-pdf/renderer",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",