@siladev/qalam 0.1.15 → 0.2.1
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/{QalamEditor-DJFh0zOj.js → QalamEditor-sYrI0Izl.js} +3871 -3693
- package/dist/QalamRenderer-CbbJYMLn.js +350 -0
- package/dist/editor/QalamEditor.d.ts.map +1 -1
- package/dist/editor/components/AutoInput.d.ts +9 -0
- package/dist/editor/components/AutoInput.d.ts.map +1 -0
- package/dist/editor/components/BlockquoteView.d.ts +3 -0
- package/dist/editor/components/BlockquoteView.d.ts.map +1 -0
- package/dist/editor/components/HadithRefView.d.ts.map +1 -1
- package/dist/editor/components/PoemView.d.ts +1 -1
- package/dist/editor/components/PoemView.d.ts.map +1 -1
- package/dist/editor/components/QuoteView.d.ts +3 -0
- package/dist/editor/components/QuoteView.d.ts.map +1 -0
- package/dist/editor/components/Toolbar.d.ts.map +1 -1
- package/dist/editor/extensions/blockquote-repeat.d.ts.map +1 -1
- package/dist/editor/extensions/poem.d.ts.map +1 -1
- package/dist/editor/extensions/quote.d.ts +12 -0
- package/dist/editor/extensions/quote.d.ts.map +1 -0
- package/dist/editor/index.js +1 -1
- package/dist/index.js +2 -2
- package/dist/renderer/QalamRenderer.d.ts.map +1 -1
- package/dist/renderer/index.js +1 -1
- package/dist/renderer/tatweel.d.ts.map +1 -1
- package/dist/resolver/index.js +18 -13
- package/dist/resolver/resolve.d.ts.map +1 -1
- package/dist/schema/index.d.ts +1 -1
- package/dist/schema/index.d.ts.map +1 -1
- package/dist/schema/index.js +58 -39
- package/dist/schema/schema.d.ts.map +1 -1
- package/dist/schema/types.d.ts +24 -2
- package/dist/schema/types.d.ts.map +1 -1
- package/dist/styles.css +228 -6
- package/package.json +1 -1
- package/dist/QalamRenderer-h6i48SCj.js +0 -309
|
@@ -1,309 +0,0 @@
|
|
|
1
|
-
import { jsx as a, jsxs as g, Fragment as $ } from "react/jsx-runtime";
|
|
2
|
-
import { useRef as H, useCallback as P, useEffect as Q, useState as F, useLayoutEffect as G } from "react";
|
|
3
|
-
const T = "ـ", J = new Set("سشصض"), K = new Set("ةهد"), U = new Set("طلكگ"), z = new Set("عقف"), M = new Set(
|
|
4
|
-
"بتثجحخسشصضطظعغفقكلمنهيئپچژگ"
|
|
5
|
-
);
|
|
6
|
-
new Set("ادذرزوأإآؤ");
|
|
7
|
-
function O(e) {
|
|
8
|
-
const t = e.charCodeAt(0);
|
|
9
|
-
return t >= 1569 && t <= 1610 || t >= 1646 && t <= 1747 || t >= 64336 && t <= 65023;
|
|
10
|
-
}
|
|
11
|
-
function A(e) {
|
|
12
|
-
const t = e.charCodeAt(0);
|
|
13
|
-
return t >= 1611 && t <= 1631;
|
|
14
|
-
}
|
|
15
|
-
function j(e, t) {
|
|
16
|
-
const n = e[t];
|
|
17
|
-
if (!M.has(n)) return !1;
|
|
18
|
-
for (let r = t + 1; r < e.length; r++)
|
|
19
|
-
if (!A(e[r]))
|
|
20
|
-
return O(e[r]);
|
|
21
|
-
return !1;
|
|
22
|
-
}
|
|
23
|
-
function V(e, t) {
|
|
24
|
-
for (let n = t + 1; n < e.length; n++)
|
|
25
|
-
if (!A(e[n])) {
|
|
26
|
-
if (O(e[n])) return !1;
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
return !0;
|
|
30
|
-
}
|
|
31
|
-
function X(e, t) {
|
|
32
|
-
for (let n = t - 1; n >= 0; n--)
|
|
33
|
-
if (!A(e[n]))
|
|
34
|
-
return M.has(e[n]);
|
|
35
|
-
return !1;
|
|
36
|
-
}
|
|
37
|
-
function Y(e) {
|
|
38
|
-
const t = [];
|
|
39
|
-
for (let n = 0; n < e.length; n++) {
|
|
40
|
-
const r = e[n];
|
|
41
|
-
if (r.includes(T)) continue;
|
|
42
|
-
let s = null;
|
|
43
|
-
for (let i = 0; i < r.length; i++) {
|
|
44
|
-
if (A(r[i])) continue;
|
|
45
|
-
const c = r[i];
|
|
46
|
-
if (J.has(c) && j(r, i)) {
|
|
47
|
-
const l = { wordIndex: n, charIndex: i + 1, priority: 1 };
|
|
48
|
-
(!s || l.priority < s.priority) && (s = l);
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
if (V(r, i) && X(r, i)) {
|
|
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
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (M.has(c) && j(r, i)) {
|
|
60
|
-
const l = { wordIndex: n, charIndex: i + 1, priority: 5 };
|
|
61
|
-
(!s || l.priority < s.priority) && (s = l);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
s && t.push(s);
|
|
65
|
-
}
|
|
66
|
-
return t;
|
|
67
|
-
}
|
|
68
|
-
function D(e, t, n = 1) {
|
|
69
|
-
return e.slice(0, t) + T.repeat(n) + e.slice(t);
|
|
70
|
-
}
|
|
71
|
-
function Z(e, t, n, r = 50) {
|
|
72
|
-
let s = e, i = t(s);
|
|
73
|
-
if (i >= n) return s;
|
|
74
|
-
for (let c = 0; c < r; c++) {
|
|
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
|
-
if (u.length === 0) break;
|
|
79
|
-
for (const { word: p, index: f } of u) {
|
|
80
|
-
const q = p.indexOf(T);
|
|
81
|
-
if (l[f] = D(p, q, 1), s = l.join(" "), i = t(s), i >= n) return s;
|
|
82
|
-
}
|
|
83
|
-
continue;
|
|
84
|
-
}
|
|
85
|
-
o.sort((u, p) => u.priority - p.priority);
|
|
86
|
-
const d = o[0];
|
|
87
|
-
if (l[d.wordIndex] = D(l[d.wordIndex], d.charIndex), s = l.join(" "), i = t(s), i >= n) return s;
|
|
88
|
-
}
|
|
89
|
-
return s;
|
|
90
|
-
}
|
|
91
|
-
function E(e) {
|
|
92
|
-
if (e === 2) return "(مرتان)";
|
|
93
|
-
const t = e.toString().replace(/\d/g, (n) => "٠١٢٣٤٥٦٧٨٩"[parseInt(n)]);
|
|
94
|
-
return e > 10 ? `(${t} مرة)` : `(${t} مرات)`;
|
|
95
|
-
}
|
|
96
|
-
function B(e, t, n) {
|
|
97
|
-
if (n >= t.length) return /* @__PURE__ */ a($, { children: e });
|
|
98
|
-
const r = t[n], s = B(e, t, n + 1);
|
|
99
|
-
switch (r.type) {
|
|
100
|
-
case "bold":
|
|
101
|
-
return /* @__PURE__ */ a("strong", { children: s });
|
|
102
|
-
case "italic":
|
|
103
|
-
return /* @__PURE__ */ a("em", { children: s });
|
|
104
|
-
case "link":
|
|
105
|
-
return /* @__PURE__ */ a("a", { href: r.attrs.href, target: r.attrs.target ?? "_blank", rel: "noopener noreferrer", children: s });
|
|
106
|
-
case "repeat":
|
|
107
|
-
return /* @__PURE__ */ g("span", { className: "qalam-render-inline-repeat", children: [
|
|
108
|
-
s,
|
|
109
|
-
/* @__PURE__ */ a("span", { className: "qalam-render-inline-repeat-badge", children: E(r.attrs.count) })
|
|
110
|
-
] });
|
|
111
|
-
case "propheticSpeech":
|
|
112
|
-
return /* @__PURE__ */ a("span", { className: "qalam-render-prophetic-speech", children: s });
|
|
113
|
-
default:
|
|
114
|
-
return s;
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
function ee({ node: e }) {
|
|
118
|
-
return e.marks?.length ? B(e.text, e.marks, 0) : /* @__PURE__ */ a($, { children: e.text });
|
|
119
|
-
}
|
|
120
|
-
function te({ seg: e, index: t }) {
|
|
121
|
-
const n = /* @__PURE__ */ a("span", { className: "qalam-render-verse", children: e.textHafsSmart });
|
|
122
|
-
return e.repeat > 1 ? /* @__PURE__ */ g($, { children: [
|
|
123
|
-
/* @__PURE__ */ a("span", { className: "qalam-render-repeat", children: n }),
|
|
124
|
-
/* @__PURE__ */ a("span", { className: "qalam-render-repeat-badge", children: E(e.repeat) })
|
|
125
|
-
] }) : n;
|
|
126
|
-
}
|
|
127
|
-
function ne({ node: e }) {
|
|
128
|
-
const { resolved: t } = e, n = t.segments.map((s) => s.textCopy).join(" "), r = t.basmalah ? `بِسْمِ اللَّهِ الرَّحْمَـٰنِ الرَّحِيمِ ${n}` : n;
|
|
129
|
-
return /* @__PURE__ */ g("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__ */ g("span", { "aria-hidden": "true", children: [
|
|
132
|
-
/* @__PURE__ */ a("span", { className: "qalam-render-bracket", children: "﴿" }),
|
|
133
|
-
t.basmalah && /* @__PURE__ */ g($, { children: [
|
|
134
|
-
/* @__PURE__ */ a("span", { className: "qalam-render-basmalah", children: "" }),
|
|
135
|
-
" "
|
|
136
|
-
] }),
|
|
137
|
-
t.segments.map((s, i) => /* @__PURE__ */ g("span", { children: [
|
|
138
|
-
i > 0 && " ",
|
|
139
|
-
/* @__PURE__ */ a(te, { seg: s, index: i })
|
|
140
|
-
] }, i)),
|
|
141
|
-
/* @__PURE__ */ a("span", { className: "qalam-render-bracket", children: "﴾" })
|
|
142
|
-
] }),
|
|
143
|
-
e.attrs.showCitation !== !1 && /* @__PURE__ */ a("span", { className: "qalam-render-citation", children: t.citation })
|
|
144
|
-
] });
|
|
145
|
-
}
|
|
146
|
-
function re(e) {
|
|
147
|
-
return e.type !== "text" ? !1 : e.marks?.some((t) => t.type === "propheticSpeech") ?? !1;
|
|
148
|
-
}
|
|
149
|
-
function ae({ node: e }) {
|
|
150
|
-
const { attrs: t, content: n } = e;
|
|
151
|
-
if (!n || n.length === 0)
|
|
152
|
-
return /* @__PURE__ */ a("span", { className: "qalam-render-hadith qalam-render-hadith--empty", children: "[حديث]" });
|
|
153
|
-
const r = n.map((c) => re(c));
|
|
154
|
-
let s = !0;
|
|
155
|
-
for (; s; ) {
|
|
156
|
-
s = !1;
|
|
157
|
-
for (let c = 0; c < n.length; c++)
|
|
158
|
-
n[c].type === "quranRef" && !r[c] && (c > 0 && r[c - 1] || c < n.length - 1 && r[c + 1]) && (r[c] = !0, s = !0);
|
|
159
|
-
}
|
|
160
|
-
const i = [];
|
|
161
|
-
for (let c = 0; c < n.length; c++)
|
|
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}`));
|
|
163
|
-
return /* @__PURE__ */ g("span", { className: "qalam-render-hadith", children: [
|
|
164
|
-
/* @__PURE__ */ a("span", { className: "qalam-render-hadith-bracket", children: "«" }),
|
|
165
|
-
i,
|
|
166
|
-
/* @__PURE__ */ a("span", { className: "qalam-render-hadith-bracket", children: "»" }),
|
|
167
|
-
t.citation && /* @__PURE__ */ a("span", { className: "qalam-render-hadith-citation", children: t.citation }),
|
|
168
|
-
t.grade && /* @__PURE__ */ g("span", { className: "qalam-render-hadith-grade", children: [
|
|
169
|
-
"(",
|
|
170
|
-
t.grade,
|
|
171
|
-
")"
|
|
172
|
-
] })
|
|
173
|
-
] });
|
|
174
|
-
}
|
|
175
|
-
function _({ node: e }) {
|
|
176
|
-
switch (e.type) {
|
|
177
|
-
case "text":
|
|
178
|
-
return /* @__PURE__ */ a(ee, { node: e });
|
|
179
|
-
case "quranRef":
|
|
180
|
-
return /* @__PURE__ */ a(ne, { node: e });
|
|
181
|
-
case "hadithRef":
|
|
182
|
-
return /* @__PURE__ */ a(ae, { node: e });
|
|
183
|
-
case "hardBreak":
|
|
184
|
-
return /* @__PURE__ */ a("br", {});
|
|
185
|
-
default:
|
|
186
|
-
return null;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
function se({ node: e }) {
|
|
190
|
-
const t = H(null), [n, r] = F(null), [s, i] = F(!1), [c, l] = F(void 0);
|
|
191
|
-
return G(() => {
|
|
192
|
-
const o = t.current;
|
|
193
|
-
if (!o) return;
|
|
194
|
-
const d = document.createElement("span");
|
|
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;
|
|
197
|
-
let q = 1;
|
|
198
|
-
for (const h of e.content)
|
|
199
|
-
!h.attrs.separator && h.attrs.parts.length > q && (q = h.attrs.parts.length);
|
|
200
|
-
const R = p / q, b = R - f;
|
|
201
|
-
let y = !1, k = 0;
|
|
202
|
-
const C = [];
|
|
203
|
-
for (let h = 0; h < e.content.length; h++) {
|
|
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 && (y = !0));
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
i(y);
|
|
212
|
-
const m = k * 1.3 + f, S = Math.min(m, R), v = y ? k : S - f;
|
|
213
|
-
l(y ? p : Math.min(S * q, p));
|
|
214
|
-
const x = /* @__PURE__ */ new Map();
|
|
215
|
-
for (const { key: h, text: N, naturalWidth: w } of C) {
|
|
216
|
-
if (!N) {
|
|
217
|
-
x.set(h, N);
|
|
218
|
-
continue;
|
|
219
|
-
}
|
|
220
|
-
w >= v ? x.set(h, N) : x.set(h, Z(N, u, v));
|
|
221
|
-
}
|
|
222
|
-
o.removeChild(d), r(x);
|
|
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(
|
|
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) => {
|
|
225
|
-
const f = `${d}-${p}`, q = n?.get(f) ?? u;
|
|
226
|
-
return /* @__PURE__ */ a(
|
|
227
|
-
"span",
|
|
228
|
-
{
|
|
229
|
-
className: "qalam-render-poem__shatr",
|
|
230
|
-
"data-shatr-key": f,
|
|
231
|
-
"data-shatr-text": u,
|
|
232
|
-
children: q
|
|
233
|
-
},
|
|
234
|
-
p
|
|
235
|
-
);
|
|
236
|
-
}) }, d)
|
|
237
|
-
) });
|
|
238
|
-
}
|
|
239
|
-
function L({ node: e }) {
|
|
240
|
-
switch (e.type) {
|
|
241
|
-
case "paragraph": {
|
|
242
|
-
const t = e.attrs?.repeat ?? 1;
|
|
243
|
-
return t > 1 ? /* @__PURE__ */ g("p", { className: "qalam-render-block-repeat", children: [
|
|
244
|
-
e.content?.map((n, r) => /* @__PURE__ */ a(_, { node: n }, r)),
|
|
245
|
-
/* @__PURE__ */ a("span", { className: "qalam-render-block-repeat-ghost", children: E(t) }),
|
|
246
|
-
/* @__PURE__ */ a("span", { className: "qalam-render-block-repeat-badge", children: E(t) })
|
|
247
|
-
] }) : /* @__PURE__ */ a("p", { children: e.content?.map((n, r) => /* @__PURE__ */ a(_, { node: n }, r)) });
|
|
248
|
-
}
|
|
249
|
-
case "heading": {
|
|
250
|
-
const t = `h${e.attrs.level}`;
|
|
251
|
-
return /* @__PURE__ */ a(t, { children: e.content?.map((n, r) => /* @__PURE__ */ a(_, { node: n }, r)) });
|
|
252
|
-
}
|
|
253
|
-
case "bulletList":
|
|
254
|
-
return /* @__PURE__ */ a("ul", { children: e.content.map((t, n) => /* @__PURE__ */ a("li", { children: t.content.map((r, s) => /* @__PURE__ */ a(L, { node: r }, s)) }, n)) });
|
|
255
|
-
case "orderedList":
|
|
256
|
-
return /* @__PURE__ */ a("ol", { ...e.attrs?.listType === "abjad" ? { "data-list-type": "abjad", style: { "--qalam-ol-style": "abjad" } } : {}, children: e.content.map((t, n) => /* @__PURE__ */ a("li", { children: t.content.map((r, s) => /* @__PURE__ */ a(L, { node: r }, s)) }, n)) });
|
|
257
|
-
case "blockquote": {
|
|
258
|
-
const t = e.attrs?.repeat ?? 1;
|
|
259
|
-
return /* @__PURE__ */ g("blockquote", { className: t > 1 ? "qalam-render-block-repeat" : void 0, children: [
|
|
260
|
-
e.content.map((n, r) => /* @__PURE__ */ a(L, { node: n }, r)),
|
|
261
|
-
t > 1 && /* @__PURE__ */ a("span", { className: "qalam-render-block-repeat-badge", children: E(t) })
|
|
262
|
-
] });
|
|
263
|
-
}
|
|
264
|
-
case "poem":
|
|
265
|
-
return /* @__PURE__ */ a(se, { node: e });
|
|
266
|
-
default:
|
|
267
|
-
return null;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
function le({ doc: e, className: t, dir: n = "rtl" }) {
|
|
271
|
-
const r = H(null), s = P((i) => {
|
|
272
|
-
const c = window.getSelection();
|
|
273
|
-
if (!c || c.isCollapsed) return;
|
|
274
|
-
const l = r.current;
|
|
275
|
-
if (!l) return;
|
|
276
|
-
const o = c.getRangeAt(0), d = l.querySelectorAll(".qalam-render-quran");
|
|
277
|
-
let u = !1;
|
|
278
|
-
for (const m of d)
|
|
279
|
-
if (o.intersectsNode(m)) {
|
|
280
|
-
u = !0;
|
|
281
|
-
break;
|
|
282
|
-
}
|
|
283
|
-
if (!u) return;
|
|
284
|
-
i.preventDefault();
|
|
285
|
-
const p = o.cloneRange();
|
|
286
|
-
for (const m of d)
|
|
287
|
-
o.intersectsNode(m) && (m.contains(o.startContainer) && p.setStartBefore(m), m.contains(o.endContainer) && p.setEndAfter(m));
|
|
288
|
-
const f = p.cloneContents(), q = document.createTreeWalker(f, NodeFilter.SHOW_ELEMENT), R = [];
|
|
289
|
-
let b = q.currentNode;
|
|
290
|
-
for (; b; )
|
|
291
|
-
b instanceof HTMLElement && b.classList.contains("qalam-render-quran") && R.push(b), b = q.nextNode();
|
|
292
|
-
for (const m of R) {
|
|
293
|
-
const S = m.dataset.copy || "", v = m.dataset.citation || "", x = document.createElement("span");
|
|
294
|
-
x.textContent = `﴿${S}﴾ [${v}]`, m.replaceWith(x);
|
|
295
|
-
}
|
|
296
|
-
const y = document.createElement("div");
|
|
297
|
-
y.appendChild(f), document.body.appendChild(y);
|
|
298
|
-
const k = y.innerText, C = y.innerHTML;
|
|
299
|
-
document.body.removeChild(y), i.clipboardData?.setData("text/plain", k), i.clipboardData?.setData("text/html", C);
|
|
300
|
-
}, []);
|
|
301
|
-
return Q(() => {
|
|
302
|
-
const i = r.current;
|
|
303
|
-
if (i)
|
|
304
|
-
return i.addEventListener("copy", s), () => i.removeEventListener("copy", s);
|
|
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)) });
|
|
306
|
-
}
|
|
307
|
-
export {
|
|
308
|
-
le as Q
|
|
309
|
-
};
|