@siladev/qalam 0.1.4 → 0.1.5
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { jsx as a, jsxs as
|
|
1
|
+
import { jsx as a, jsxs as y, Fragment as $ } from "react/jsx-runtime";
|
|
2
2
|
import { useRef as H, useCallback as P, useEffect as Q, useState as F, useLayoutEffect as G } from "react";
|
|
3
3
|
const T = "ـ", J = new Set("سشصض"), K = new Set("ةهد"), U = new Set("طلكگ"), z = new Set("عقف"), M = new Set(
|
|
4
4
|
"بتثجحخسشصضطظعغفقكلمنهيئپچژگ"
|
|
@@ -44,21 +44,21 @@ function Y(e) {
|
|
|
44
44
|
if (A(r[i])) continue;
|
|
45
45
|
const c = r[i];
|
|
46
46
|
if (J.has(c) && D(r, i)) {
|
|
47
|
-
const
|
|
48
|
-
(!s ||
|
|
47
|
+
const l = { wordIndex: n, charIndex: i + 1, priority: 1 };
|
|
48
|
+
(!s || l.priority < s.priority) && (s = l);
|
|
49
49
|
continue;
|
|
50
50
|
}
|
|
51
51
|
if (V(r, i) && X(r, i)) {
|
|
52
|
-
let
|
|
53
|
-
if (K.has(c) ?
|
|
54
|
-
const
|
|
55
|
-
(!s ||
|
|
52
|
+
let l = 0;
|
|
53
|
+
if (K.has(c) ? l = 2 : U.has(c) ? l = 3 : z.has(c) && (l = 4), l > 0) {
|
|
54
|
+
const o = { wordIndex: n, charIndex: i, priority: l };
|
|
55
|
+
(!s || o.priority < s.priority) && (s = o);
|
|
56
56
|
continue;
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
if (M.has(c) && D(r, i)) {
|
|
60
|
-
const
|
|
61
|
-
(!s ||
|
|
60
|
+
const l = { wordIndex: n, charIndex: i + 1, priority: 5 };
|
|
61
|
+
(!s || l.priority < s.priority) && (s = l);
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
64
|
s && t.push(s);
|
|
@@ -72,19 +72,19 @@ function Z(e, t, n, r = 50) {
|
|
|
72
72
|
let s = e, i = t(s);
|
|
73
73
|
if (i >= n) return s;
|
|
74
74
|
for (let c = 0; c < r; c++) {
|
|
75
|
-
const
|
|
76
|
-
if (
|
|
77
|
-
const u =
|
|
75
|
+
const l = s.split(" "), o = Y(l);
|
|
76
|
+
if (o.length === 0) {
|
|
77
|
+
const u = l.map((p, f) => ({ word: p, index: f })).filter(({ word: p }) => p.includes(T));
|
|
78
78
|
if (u.length === 0) break;
|
|
79
79
|
for (const { word: p, index: f } of u) {
|
|
80
80
|
const q = p.indexOf(T);
|
|
81
|
-
if (
|
|
81
|
+
if (l[f] = j(p, q, 1), s = l.join(" "), i = t(s), i >= n) return s;
|
|
82
82
|
}
|
|
83
83
|
continue;
|
|
84
84
|
}
|
|
85
|
-
|
|
86
|
-
const d =
|
|
87
|
-
if (
|
|
85
|
+
o.sort((u, p) => u.priority - p.priority);
|
|
86
|
+
const d = o[0];
|
|
87
|
+
if (l[d.wordIndex] = j(l[d.wordIndex], d.charIndex), s = l.join(" "), i = t(s), i >= n) return s;
|
|
88
88
|
}
|
|
89
89
|
return s;
|
|
90
90
|
}
|
|
@@ -104,7 +104,7 @@ function B(e, t, n) {
|
|
|
104
104
|
case "link":
|
|
105
105
|
return /* @__PURE__ */ a("a", { href: r.attrs.href, target: r.attrs.target ?? "_blank", rel: "noopener noreferrer", children: s });
|
|
106
106
|
case "repeat":
|
|
107
|
-
return /* @__PURE__ */
|
|
107
|
+
return /* @__PURE__ */ y("span", { className: "qalam-render-inline-repeat", children: [
|
|
108
108
|
s,
|
|
109
109
|
/* @__PURE__ */ a("span", { className: "qalam-render-inline-repeat-badge", children: E(r.attrs.count) })
|
|
110
110
|
] });
|
|
@@ -119,24 +119,27 @@ function ee({ node: e }) {
|
|
|
119
119
|
}
|
|
120
120
|
function te({ seg: e, index: t }) {
|
|
121
121
|
const n = /* @__PURE__ */ a("span", { className: "qalam-render-verse", children: e.textHafsSmart });
|
|
122
|
-
return e.repeat > 1 ? /* @__PURE__ */
|
|
122
|
+
return e.repeat > 1 ? /* @__PURE__ */ y($, { children: [
|
|
123
123
|
/* @__PURE__ */ a("span", { className: "qalam-render-repeat", children: n }),
|
|
124
124
|
/* @__PURE__ */ a("span", { className: "qalam-render-repeat-badge", children: E(e.repeat) })
|
|
125
125
|
] }) : n;
|
|
126
126
|
}
|
|
127
127
|
function ne({ node: e }) {
|
|
128
128
|
const { resolved: t } = e, n = t.segments.map((s) => s.textCopy).join(" "), r = t.basmalah ? `بِسْمِ اللَّهِ الرَّحْمَـٰنِ الرَّحِيمِ ${n}` : n;
|
|
129
|
-
return /* @__PURE__ */
|
|
130
|
-
/* @__PURE__ */ a("span", { className: "qalam-render-
|
|
131
|
-
|
|
132
|
-
/* @__PURE__ */ a("span", { className: "qalam-render-
|
|
133
|
-
|
|
129
|
+
return /* @__PURE__ */ y("span", { className: "qalam-render-quran", "data-copy": r, "data-citation": t.citation, children: [
|
|
130
|
+
/* @__PURE__ */ a("span", { className: "qalam-render-seo", "aria-hidden": "false", children: r }),
|
|
131
|
+
/* @__PURE__ */ y("span", { "aria-hidden": "true", children: [
|
|
132
|
+
/* @__PURE__ */ a("span", { className: "qalam-render-bracket", children: "﴿" }),
|
|
133
|
+
t.basmalah && /* @__PURE__ */ y($, { children: [
|
|
134
|
+
/* @__PURE__ */ a("span", { className: "qalam-render-basmalah", children: "" }),
|
|
135
|
+
" "
|
|
136
|
+
] }),
|
|
137
|
+
t.segments.map((s, i) => /* @__PURE__ */ y("span", { children: [
|
|
138
|
+
i > 0 && " ",
|
|
139
|
+
/* @__PURE__ */ a(te, { seg: s, index: i })
|
|
140
|
+
] }, i)),
|
|
141
|
+
/* @__PURE__ */ a("span", { className: "qalam-render-bracket", children: "﴾" })
|
|
134
142
|
] }),
|
|
135
|
-
t.segments.map((s, i) => /* @__PURE__ */ N("span", { children: [
|
|
136
|
-
i > 0 && " ",
|
|
137
|
-
/* @__PURE__ */ a(te, { seg: s, index: i })
|
|
138
|
-
] }, i)),
|
|
139
|
-
/* @__PURE__ */ a("span", { className: "qalam-render-bracket", children: "﴾" }),
|
|
140
143
|
e.attrs.showCitation !== !1 && /* @__PURE__ */ a("span", { className: "qalam-render-citation", children: t.citation })
|
|
141
144
|
] });
|
|
142
145
|
}
|
|
@@ -157,12 +160,12 @@ function ae({ node: e }) {
|
|
|
157
160
|
const i = [];
|
|
158
161
|
for (let c = 0; c < n.length; c++)
|
|
159
162
|
r[c] && (c === 0 || !r[c - 1]) && i.push(/* @__PURE__ */ a("span", { className: "qalam-render-prophetic-quote", children: "”" }, `q-open-${c}`)), i.push(/* @__PURE__ */ a(_, { node: n[c] }, c)), r[c] && (c === n.length - 1 || !r[c + 1]) && i.push(/* @__PURE__ */ a("span", { className: "qalam-render-prophetic-quote", children: "“" }, `q-close-${c}`));
|
|
160
|
-
return /* @__PURE__ */
|
|
163
|
+
return /* @__PURE__ */ y("span", { className: "qalam-render-hadith", children: [
|
|
161
164
|
/* @__PURE__ */ a("span", { className: "qalam-render-hadith-bracket", children: "«" }),
|
|
162
165
|
i,
|
|
163
166
|
/* @__PURE__ */ a("span", { className: "qalam-render-hadith-bracket", children: "»" }),
|
|
164
167
|
t.citation && /* @__PURE__ */ a("span", { className: "qalam-render-hadith-citation", children: t.citation }),
|
|
165
|
-
t.grade && /* @__PURE__ */
|
|
168
|
+
t.grade && /* @__PURE__ */ y("span", { className: "qalam-render-hadith-grade", children: [
|
|
166
169
|
"(",
|
|
167
170
|
t.grade,
|
|
168
171
|
")"
|
|
@@ -184,13 +187,13 @@ function _({ node: e }) {
|
|
|
184
187
|
}
|
|
185
188
|
}
|
|
186
189
|
function se({ node: e }) {
|
|
187
|
-
const t = H(null), [n, r] = F(null), [s, i] = F(!1), [c,
|
|
190
|
+
const t = H(null), [n, r] = F(null), [s, i] = F(!1), [c, l] = F(void 0);
|
|
188
191
|
return G(() => {
|
|
189
|
-
const
|
|
190
|
-
if (!
|
|
192
|
+
const o = t.current;
|
|
193
|
+
if (!o) return;
|
|
191
194
|
const d = document.createElement("span");
|
|
192
|
-
d.className = "qalam-render-poem__shatr", d.style.position = "absolute", d.style.visibility = "hidden", d.style.whiteSpace = "nowrap", d.style.width = "auto",
|
|
193
|
-
const u = (h) => (d.textContent = h, d.scrollWidth), p =
|
|
195
|
+
d.className = "qalam-render-poem__shatr", d.style.position = "absolute", d.style.visibility = "hidden", d.style.whiteSpace = "nowrap", d.style.width = "auto", o.appendChild(d);
|
|
196
|
+
const u = (h) => (d.textContent = h, d.scrollWidth), p = o.parentElement?.clientWidth ?? o.clientWidth, f = 32;
|
|
194
197
|
let q = 1;
|
|
195
198
|
for (const h of e.content)
|
|
196
199
|
!h.attrs.separator && h.attrs.parts.length > q && (q = h.attrs.parts.length);
|
|
@@ -198,27 +201,27 @@ function se({ node: e }) {
|
|
|
198
201
|
let g = !1, k = 0;
|
|
199
202
|
const C = [];
|
|
200
203
|
for (let h = 0; h < e.content.length; h++) {
|
|
201
|
-
const
|
|
202
|
-
if (!
|
|
203
|
-
for (let w = 0; w <
|
|
204
|
-
const I =
|
|
205
|
-
C.push({ key: `${h}-${w}`, text: I, naturalWidth: W }), I && (W > k && (k = W),
|
|
204
|
+
const N = e.content[h];
|
|
205
|
+
if (!N.attrs.separator)
|
|
206
|
+
for (let w = 0; w < N.attrs.parts.length; w++) {
|
|
207
|
+
const I = N.attrs.parts[w], W = I ? u(I) : 0;
|
|
208
|
+
C.push({ key: `${h}-${w}`, text: I, naturalWidth: W }), I && (W > k && (k = W), N.attrs.parts.length > 1 && W > b && (g = !0));
|
|
206
209
|
}
|
|
207
210
|
}
|
|
208
211
|
i(g);
|
|
209
212
|
const m = k * 1.3 + f, S = Math.min(m, R), v = g ? k : S - f;
|
|
210
|
-
|
|
213
|
+
l(g ? p : Math.min(S * q, p));
|
|
211
214
|
const x = /* @__PURE__ */ new Map();
|
|
212
|
-
for (const { key: h, text:
|
|
213
|
-
if (!
|
|
214
|
-
x.set(h,
|
|
215
|
+
for (const { key: h, text: N, naturalWidth: w } of C) {
|
|
216
|
+
if (!N) {
|
|
217
|
+
x.set(h, N);
|
|
215
218
|
continue;
|
|
216
219
|
}
|
|
217
|
-
w >= v ? x.set(h,
|
|
220
|
+
w >= v ? x.set(h, N) : x.set(h, Z(N, u, v));
|
|
218
221
|
}
|
|
219
|
-
|
|
222
|
+
o.removeChild(d), r(x);
|
|
220
223
|
}, [e]), /* @__PURE__ */ a("div", { ref: t, className: `qalam-render-poem${s ? " qalam-render-poem--stacked" : ""}`, style: c ? { maxWidth: c } : void 0, children: e.content.map(
|
|
221
|
-
(
|
|
224
|
+
(o, d) => o.attrs.separator ? /* @__PURE__ */ a("div", { className: "qalam-render-poem__separator", children: "* * *" }, d) : /* @__PURE__ */ a("div", { className: "qalam-render-poem__bayt", children: o.attrs.parts.map((u, p) => {
|
|
222
225
|
const f = `${d}-${p}`, q = n?.get(f) ?? u;
|
|
223
226
|
return /* @__PURE__ */ a(
|
|
224
227
|
"span",
|
|
@@ -237,7 +240,7 @@ function L({ node: e }) {
|
|
|
237
240
|
switch (e.type) {
|
|
238
241
|
case "paragraph": {
|
|
239
242
|
const t = e.attrs?.repeat ?? 1;
|
|
240
|
-
return t > 1 ? /* @__PURE__ */
|
|
243
|
+
return t > 1 ? /* @__PURE__ */ y("p", { className: "qalam-render-block-repeat", children: [
|
|
241
244
|
e.content?.map((n, r) => /* @__PURE__ */ a(_, { node: n }, r)),
|
|
242
245
|
/* @__PURE__ */ a("span", { className: "qalam-render-block-repeat-ghost", children: E(t) }),
|
|
243
246
|
/* @__PURE__ */ a("span", { className: "qalam-render-block-repeat-badge", children: E(t) })
|
|
@@ -253,7 +256,7 @@ function L({ node: e }) {
|
|
|
253
256
|
return /* @__PURE__ */ a("ol", { ...e.attrs?.listType === "abjad" ? { "data-list-type": "abjad" } : {}, children: e.content.map((t, n) => /* @__PURE__ */ a("li", { children: t.content.map((r, s) => /* @__PURE__ */ a(L, { node: r }, s)) }, n)) });
|
|
254
257
|
case "blockquote": {
|
|
255
258
|
const t = e.attrs?.repeat ?? 1;
|
|
256
|
-
return /* @__PURE__ */
|
|
259
|
+
return /* @__PURE__ */ y("blockquote", { className: t > 1 ? "qalam-render-block-repeat" : void 0, children: [
|
|
257
260
|
e.content.map((n, r) => /* @__PURE__ */ a(L, { node: n }, r)),
|
|
258
261
|
t > 1 && /* @__PURE__ */ a("span", { className: "qalam-render-block-repeat-badge", children: E(t) })
|
|
259
262
|
] });
|
|
@@ -264,24 +267,24 @@ function L({ node: e }) {
|
|
|
264
267
|
return null;
|
|
265
268
|
}
|
|
266
269
|
}
|
|
267
|
-
function
|
|
270
|
+
function le({ doc: e, className: t, dir: n = "rtl" }) {
|
|
268
271
|
const r = H(null), s = P((i) => {
|
|
269
272
|
const c = window.getSelection();
|
|
270
273
|
if (!c || c.isCollapsed) return;
|
|
271
|
-
const
|
|
272
|
-
if (!
|
|
273
|
-
const
|
|
274
|
+
const l = r.current;
|
|
275
|
+
if (!l) return;
|
|
276
|
+
const o = c.getRangeAt(0), d = l.querySelectorAll(".qalam-render-quran");
|
|
274
277
|
let u = !1;
|
|
275
278
|
for (const m of d)
|
|
276
|
-
if (
|
|
279
|
+
if (o.intersectsNode(m)) {
|
|
277
280
|
u = !0;
|
|
278
281
|
break;
|
|
279
282
|
}
|
|
280
283
|
if (!u) return;
|
|
281
284
|
i.preventDefault();
|
|
282
|
-
const p =
|
|
285
|
+
const p = o.cloneRange();
|
|
283
286
|
for (const m of d)
|
|
284
|
-
|
|
287
|
+
o.intersectsNode(m) && (m.contains(o.startContainer) && p.setStartBefore(m), m.contains(o.endContainer) && p.setEndAfter(m));
|
|
285
288
|
const f = p.cloneContents(), q = document.createTreeWalker(f, NodeFilter.SHOW_ELEMENT), R = [];
|
|
286
289
|
let b = q.currentNode;
|
|
287
290
|
for (; b; )
|
|
@@ -302,5 +305,5 @@ function oe({ doc: e, className: t, dir: n = "rtl" }) {
|
|
|
302
305
|
}, [s]), /* @__PURE__ */ a("div", { ref: r, className: `qalam-renderer ${t ?? ""}`, dir: n, children: e.content.map((i, c) => /* @__PURE__ */ a(L, { node: i }, c)) });
|
|
303
306
|
}
|
|
304
307
|
export {
|
|
305
|
-
|
|
308
|
+
le as Q
|
|
306
309
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { validateAST as e } from "./schema/index.js";
|
|
2
2
|
import { Q as s, a as t } from "./QalamEditor-BV95C4EV.js";
|
|
3
|
-
import { Q as f } from "./QalamRenderer-
|
|
3
|
+
import { Q as f } from "./QalamRenderer-DrrLH1Fg.js";
|
|
4
4
|
import { resolveAST as d } from "./resolver/index.js";
|
|
5
5
|
import { g as Q, a as p, b as u, i as S, l as g, r as i } from "./lookup-CFbcujyG.js";
|
|
6
6
|
export {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QalamRenderer.d.ts","sourceRoot":"","sources":["../../src/renderer/QalamRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EASjB,MAAM,iBAAiB,CAAC;AAIzB,UAAU,kBAAkB;IAC1B,GAAG,EAAE,gBAAgB,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;CACrB;
|
|
1
|
+
{"version":3,"file":"QalamRenderer.d.ts","sourceRoot":"","sources":["../../src/renderer/QalamRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EASjB,MAAM,iBAAiB,CAAC;AAIzB,UAAU,kBAAkB;IAC1B,GAAG,EAAE,gBAAgB,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC;CACrB;AAqVD,wBAAgB,aAAa,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,GAAW,EAAE,EAAE,kBAAkB,2CAmFhF"}
|
package/dist/renderer/index.js
CHANGED
package/dist/styles.css
CHANGED
|
@@ -478,6 +478,18 @@ ol[data-list-type="abjad"] {
|
|
|
478
478
|
}
|
|
479
479
|
|
|
480
480
|
|
|
481
|
+
.qalam-render-seo {
|
|
482
|
+
position: absolute;
|
|
483
|
+
width: 1px;
|
|
484
|
+
height: 1px;
|
|
485
|
+
padding: 0;
|
|
486
|
+
margin: -1px;
|
|
487
|
+
overflow: hidden;
|
|
488
|
+
clip: rect(0, 0, 0, 0);
|
|
489
|
+
white-space: nowrap;
|
|
490
|
+
border: 0;
|
|
491
|
+
}
|
|
492
|
+
|
|
481
493
|
.qalam-render-verse {
|
|
482
494
|
font-family: "HafsSmart", serif;
|
|
483
495
|
font-size: 1.1em;
|