@taloswork/ose-shared 0.1.10 → 0.1.12
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/package.json +3 -3
- package/skills/document/SKILL.md +143 -215
- package/skills/document/art-directions/base.css +27 -2
- package/skills/document/art-directions/cinematic-depth.css +3 -1
- package/skills/document/art-directions/collage-paper.css +5 -1
- package/skills/document/art-directions/editorial-cut.css +5 -1
- package/skills/document/art-directions/geometric-pop.css +6 -0
- package/skills/document/art-directions/gradient-mesh.css +5 -1
- package/skills/document/art-directions/illustrated-doodle.css +5 -0
- package/skills/document/art-directions/luxury-ornament.css +4 -1
- package/skills/document/art-directions/maximalist-blocks.css +6 -0
- package/skills/document/art-directions/technical-grid.css +4 -0
- package/skills/document/assets/fonts/fonts.json +2 -2
- package/skills/document/assets/pdf-fonts/NotoSansSC-PDF-Bold.ttf +0 -0
- package/skills/document/assets/pdf-fonts/NotoSansSC-PDF-Regular.ttf +0 -0
- package/skills/document/assets/pdf-fonts/OFL.txt +93 -0
- package/skills/document/assets/pdf-fonts/README.md +35 -0
- package/skills/document/assets/tessdata/LICENSE-Apache-2.0.txt +202 -0
- package/skills/document/assets/tessdata/README.md +21 -0
- package/skills/document/assets/tessdata/chi_sim.traineddata.gz +0 -0
- package/skills/document/assets/tessdata/eng.traineddata.gz +0 -0
- package/skills/document/bin/deck-build.cjs +2311 -41
- package/skills/document/bin/deck-chart.cjs +762 -0
- package/skills/document/bin/deck-plan.cjs +802 -0
- package/skills/document/bin/deck-qa.cjs +984 -249
- package/skills/document/bin/deck-scenario.cjs +1346 -0
- package/skills/document/bin/doc-convert.cjs +130 -39
- package/skills/document/bin/doc-fill.cjs +73121 -170
- package/skills/document/bin/doc-gen.cjs +625 -68
- package/skills/document/bin/doc-run.cjs +162 -24
- package/skills/document/bin/doc-scan.cjs +13 -0
- package/skills/document/bin/doc-text.cjs +13 -0
- package/skills/document/bin/doc-validate.cjs +718 -23
- package/skills/document/bin/doc-xml.cjs +9 -5
- package/skills/document/bin/docx-annotate.cjs +95 -19
- package/skills/document/bin/fontkit.cjs +1 -0
- package/skills/document/bin/html2pptx.cjs +1372 -121
- package/skills/document/bin/ocr-worker.cjs +1 -0
- package/skills/document/bin/ocr.cjs +131 -40
- package/skills/document/bin/pdf-form.cjs +674 -177
- package/skills/document/bin/pdf-images.cjs +13 -0
- package/skills/document/bin/pdf-ops.cjs +634 -199
- package/skills/document/bin/pdf-render.cjs +19 -3
- package/skills/document/bin/pdf-tables.cjs +13 -0
- package/skills/document/bin/pptx-clone.cjs +3 -3
- package/skills/document/bin/pptx-slide.cjs +3 -3
- package/skills/document/bin/xlsx-query.cjs +192 -61
- package/skills/document/bin-reference.md +56 -33
- package/skills/document/content-pipeline.md +129 -242
- package/skills/document/deck-design.md +355 -638
- package/skills/document/layouts/README.md +46 -33
- package/skills/document/layouts/capacity.json +1 -0
- package/skills/document/layouts/slots.json +1 -1
- package/skills/document/layouts/toc-panel.tpl +1 -1
- package/skills/document/motion/README.md +3 -2
- package/skills/document/office.md +3 -3
- package/skills/document/packs/board-brief/backdrop.html +2 -0
- package/skills/document/packs/board-brief/pack.css +2 -1
- package/skills/document/packs/mckinsey-photo/backdrop.html +2 -0
- package/skills/document/packs/mckinsey-photo/pack.css +2 -1
- package/skills/document/packs/press-room/backdrop.html +2 -0
- package/skills/document/packs/press-room/pack.css +2 -1
- package/skills/document/packs/prismatic-3d/backdrop.html +2 -0
- package/skills/document/packs/prismatic-3d/pack.css +4 -1
- package/skills/document/pdf.md +53 -49
- package/skills/document/rewrite.md +241 -308
- package/skills/document/scenarios.json +1290 -0
- package/skills/document/scenarios.schema.json +103 -0
- package/skills/document/styles/README.md +15 -25
- package/skills/document/styles/_contract-defaults.css +25 -1
- package/skills/document/styles/anthropic/skin.css +6 -3
- package/skills/document/styles/apple/skin.css +4 -3
- package/skills/document/styles/bistro-warm/backdrop.html +2 -0
- package/skills/document/styles/bistro-warm/skin.css +4 -1
- package/skills/document/styles/black-gold/skin.css +6 -5
- package/skills/document/styles/bold-clash/backdrop.html +2 -0
- package/skills/document/styles/bold-clash/skin.css +2 -1
- package/skills/document/styles/branding/skin.css +4 -4
- package/skills/document/styles/campus-teal/backdrop.html +2 -0
- package/skills/document/styles/campus-teal/skin.css +2 -1
- package/skills/document/styles/cinereel/skin.css +7 -3
- package/skills/document/styles/clinic-care/backdrop.html +2 -0
- package/skills/document/styles/clinic-care/skin.css +2 -1
- package/skills/document/styles/cool/skin.css +6 -5
- package/skills/document/styles/dark-glass/backdrop.html +2 -0
- package/skills/document/styles/dark-glass/skin.css +2 -1
- package/skills/document/styles/gov-brief/backdrop.html +2 -0
- package/skills/document/styles/gov-brief/skin.css +2 -1
- package/skills/document/styles/grid-tech/backdrop.html +2 -0
- package/skills/document/styles/grid-tech/skin.css +2 -1
- package/skills/document/styles/hand-drawn/skin.css +3 -3
- package/skills/document/styles/ivory-gold/skin.css +7 -6
- package/skills/document/styles/legal-slate/backdrop.html +2 -0
- package/skills/document/styles/legal-slate/skin.css +2 -1
- package/skills/document/styles/magazine-ink/skin.css +4 -3
- package/skills/document/styles/mckinsey/skin.css +2 -1
- package/skills/document/styles/memphis/backdrop.html +2 -0
- package/skills/document/styles/memphis/skin.css +2 -1
- package/skills/document/styles/mono/skin.css +6 -2
- package/skills/document/styles/neon-cyber/backdrop.html +2 -0
- package/skills/document/styles/neon-cyber/skin.css +2 -1
- package/skills/document/styles/olive-gold/skin.css +7 -6
- package/skills/document/styles/organic-earth/backdrop.html +2 -0
- package/skills/document/styles/organic-earth/skin.css +2 -1
- package/skills/document/styles/pastel-saas/backdrop.html +2 -0
- package/skills/document/styles/pastel-saas/skin.css +2 -1
- package/skills/document/styles/portfolio-noir/backdrop.html +2 -0
- package/skills/document/styles/portfolio-noir/skin.css +2 -1
- package/skills/document/styles/retro-press/backdrop.html +2 -0
- package/skills/document/styles/retro-press/skin.css +2 -1
- package/skills/document/styles/sport-arena/backdrop.html +2 -0
- package/skills/document/styles/sport-arena/skin.css +4 -1
- package/skills/document/styles/swiss-grid/skin.css +10 -5
- package/skills/document/styles/wedding-blush/backdrop.html +2 -0
- package/skills/document/styles/wedding-blush/skin.css +4 -1
- package/skills/document/theme-system.md +85 -77
- package/skills/document/themes/README.md +7 -5
- package/skills/document/vision.md +8 -5
- package/skills/document/xlsx.md +15 -25
- package/skills/cozy-static-svg/SKILL.md +0 -76
- package/skills/cozy-static-svg/references/approved-preview.png +0 -0
- package/skills/cozy-static-svg/references/cross-platform.md +0 -73
- package/skills/cozy-static-svg/references/moon_keeps_watch.svg +0 -229
- package/skills/cozy-static-svg/references/style-anchor.md +0 -271
- package/skills/cozy-static-svg/scripts/artkit.py +0 -321
- package/skills/cozy-static-svg/scripts/to_png.py +0 -333
|
@@ -132,7 +132,7 @@ var require_runtime = __commonJS({
|
|
|
132
132
|
return { __await: arg };
|
|
133
133
|
};
|
|
134
134
|
function AsyncIterator(generator, PromiseImpl) {
|
|
135
|
-
function invoke(method, arg,
|
|
135
|
+
function invoke(method, arg, resolve2, reject) {
|
|
136
136
|
var record = tryCatch(generator[method], generator, arg);
|
|
137
137
|
if (record.type === "throw") {
|
|
138
138
|
reject(record.arg);
|
|
@@ -141,24 +141,24 @@ var require_runtime = __commonJS({
|
|
|
141
141
|
var value = result.value;
|
|
142
142
|
if (value && typeof value === "object" && hasOwn.call(value, "__await")) {
|
|
143
143
|
return PromiseImpl.resolve(value.__await).then(function(value2) {
|
|
144
|
-
invoke("next", value2,
|
|
144
|
+
invoke("next", value2, resolve2, reject);
|
|
145
145
|
}, function(err) {
|
|
146
|
-
invoke("throw", err,
|
|
146
|
+
invoke("throw", err, resolve2, reject);
|
|
147
147
|
});
|
|
148
148
|
}
|
|
149
149
|
return PromiseImpl.resolve(value).then(function(unwrapped) {
|
|
150
150
|
result.value = unwrapped;
|
|
151
|
-
|
|
151
|
+
resolve2(result);
|
|
152
152
|
}, function(error) {
|
|
153
|
-
return invoke("throw", error,
|
|
153
|
+
return invoke("throw", error, resolve2, reject);
|
|
154
154
|
});
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
var previousPromise;
|
|
158
158
|
function enqueue(method, arg) {
|
|
159
159
|
function callInvokeWithMethodAndArg() {
|
|
160
|
-
return new PromiseImpl(function(
|
|
161
|
-
invoke(method, arg,
|
|
160
|
+
return new PromiseImpl(function(resolve2, reject) {
|
|
161
|
+
invoke(method, arg, resolve2, reject);
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
164
|
return previousPromise = // If enqueue has been called before, then we want to wait until
|
|
@@ -612,13 +612,13 @@ var require_createScheduler = __commonJS({
|
|
|
612
612
|
}
|
|
613
613
|
}
|
|
614
614
|
};
|
|
615
|
-
const queue = (action, payload) => new Promise((
|
|
615
|
+
const queue = (action, payload) => new Promise((resolve2, reject) => {
|
|
616
616
|
const job = createJob({ action, payload });
|
|
617
617
|
jobQueue.push(async (w) => {
|
|
618
618
|
jobQueue.shift();
|
|
619
619
|
runningWorkers[w.id] = job;
|
|
620
620
|
try {
|
|
621
|
-
|
|
621
|
+
resolve2(await w[action].apply(exports2, [...payload, job.id]));
|
|
622
622
|
} catch (err) {
|
|
623
623
|
reject(err);
|
|
624
624
|
} finally {
|
|
@@ -6600,7 +6600,7 @@ var require_lib3 = __commonJS({
|
|
|
6600
6600
|
let accum = [];
|
|
6601
6601
|
let accumBytes = 0;
|
|
6602
6602
|
let abort = false;
|
|
6603
|
-
return new Body.Promise(function(
|
|
6603
|
+
return new Body.Promise(function(resolve2, reject) {
|
|
6604
6604
|
let resTimeout;
|
|
6605
6605
|
if (_this4.timeout) {
|
|
6606
6606
|
resTimeout = setTimeout(function() {
|
|
@@ -6634,7 +6634,7 @@ var require_lib3 = __commonJS({
|
|
|
6634
6634
|
}
|
|
6635
6635
|
clearTimeout(resTimeout);
|
|
6636
6636
|
try {
|
|
6637
|
-
|
|
6637
|
+
resolve2(Buffer.concat(accum, accumBytes));
|
|
6638
6638
|
} catch (err) {
|
|
6639
6639
|
reject(new FetchError(`Could not create Buffer from response body for ${_this4.url}: ${err.message}`, "system", err));
|
|
6640
6640
|
}
|
|
@@ -7309,7 +7309,7 @@ var require_lib3 = __commonJS({
|
|
|
7309
7309
|
throw new Error("native promise missing, set fetch.Promise to your favorite alternative");
|
|
7310
7310
|
}
|
|
7311
7311
|
Body.Promise = fetch.Promise;
|
|
7312
|
-
return new fetch.Promise(function(
|
|
7312
|
+
return new fetch.Promise(function(resolve2, reject) {
|
|
7313
7313
|
const request = new Request(url, opts);
|
|
7314
7314
|
const options = getNodeRequestOptions(request);
|
|
7315
7315
|
const send = (options.protocol === "https:" ? https : http).request;
|
|
@@ -7442,7 +7442,7 @@ var require_lib3 = __commonJS({
|
|
|
7442
7442
|
requestOpts.body = void 0;
|
|
7443
7443
|
requestOpts.headers.delete("content-length");
|
|
7444
7444
|
}
|
|
7445
|
-
|
|
7445
|
+
resolve2(fetch(new Request(locationURL, requestOpts)));
|
|
7446
7446
|
finalize();
|
|
7447
7447
|
return;
|
|
7448
7448
|
}
|
|
@@ -7463,7 +7463,7 @@ var require_lib3 = __commonJS({
|
|
|
7463
7463
|
const codings = headers.get("Content-Encoding");
|
|
7464
7464
|
if (!request.compress || request.method === "HEAD" || codings === null || res.statusCode === 204 || res.statusCode === 304) {
|
|
7465
7465
|
response = new Response(body, response_options);
|
|
7466
|
-
|
|
7466
|
+
resolve2(response);
|
|
7467
7467
|
return;
|
|
7468
7468
|
}
|
|
7469
7469
|
const zlibOptions = {
|
|
@@ -7473,7 +7473,7 @@ var require_lib3 = __commonJS({
|
|
|
7473
7473
|
if (codings == "gzip" || codings == "x-gzip") {
|
|
7474
7474
|
body = body.pipe(zlib.createGunzip(zlibOptions));
|
|
7475
7475
|
response = new Response(body, response_options);
|
|
7476
|
-
|
|
7476
|
+
resolve2(response);
|
|
7477
7477
|
return;
|
|
7478
7478
|
}
|
|
7479
7479
|
if (codings == "deflate" || codings == "x-deflate") {
|
|
@@ -7485,12 +7485,12 @@ var require_lib3 = __commonJS({
|
|
|
7485
7485
|
body = body.pipe(zlib.createInflateRaw());
|
|
7486
7486
|
}
|
|
7487
7487
|
response = new Response(body, response_options);
|
|
7488
|
-
|
|
7488
|
+
resolve2(response);
|
|
7489
7489
|
});
|
|
7490
7490
|
raw.on("end", function() {
|
|
7491
7491
|
if (!response) {
|
|
7492
7492
|
response = new Response(body, response_options);
|
|
7493
|
-
|
|
7493
|
+
resolve2(response);
|
|
7494
7494
|
}
|
|
7495
7495
|
});
|
|
7496
7496
|
return;
|
|
@@ -7498,11 +7498,11 @@ var require_lib3 = __commonJS({
|
|
|
7498
7498
|
if (codings == "br" && typeof zlib.createBrotliDecompress === "function") {
|
|
7499
7499
|
body = body.pipe(zlib.createBrotliDecompress());
|
|
7500
7500
|
response = new Response(body, response_options);
|
|
7501
|
-
|
|
7501
|
+
resolve2(response);
|
|
7502
7502
|
return;
|
|
7503
7503
|
}
|
|
7504
7504
|
response = new Response(body, response_options);
|
|
7505
|
-
|
|
7505
|
+
resolve2(response);
|
|
7506
7506
|
});
|
|
7507
7507
|
writeToStream(req, request);
|
|
7508
7508
|
});
|
|
@@ -7662,8 +7662,8 @@ var require_createWorker = __commonJS({
|
|
|
7662
7662
|
const lstmOnlyCore = [OEM.DEFAULT, OEM.LSTM_ONLY].includes(oem) && !options.legacyCore;
|
|
7663
7663
|
let workerResReject;
|
|
7664
7664
|
let workerResResolve;
|
|
7665
|
-
const workerRes = new Promise((
|
|
7666
|
-
workerResResolve =
|
|
7665
|
+
const workerRes = new Promise((resolve2, reject) => {
|
|
7666
|
+
workerResResolve = resolve2;
|
|
7667
7667
|
workerResReject = reject;
|
|
7668
7668
|
});
|
|
7669
7669
|
const workerError = (event) => {
|
|
@@ -7678,10 +7678,10 @@ var require_createWorker = __commonJS({
|
|
|
7678
7678
|
const setReject = (promiseId, rej) => {
|
|
7679
7679
|
rejects[promiseId] = rej;
|
|
7680
7680
|
};
|
|
7681
|
-
const startJob = ({ id: jobId, action, payload }) => new Promise((
|
|
7681
|
+
const startJob = ({ id: jobId, action, payload }) => new Promise((resolve2, reject) => {
|
|
7682
7682
|
log(`[${id}]: Start ${jobId}, action=${action}`);
|
|
7683
7683
|
const promiseId = `${action}-${jobId}`;
|
|
7684
|
-
setResolve(promiseId,
|
|
7684
|
+
setResolve(promiseId, resolve2);
|
|
7685
7685
|
setReject(promiseId, reject);
|
|
7686
7686
|
send(worker, {
|
|
7687
7687
|
workerId: id,
|
|
@@ -8025,34 +8025,124 @@ var require_src = __commonJS({
|
|
|
8025
8025
|
|
|
8026
8026
|
// apps/admin/data/skills.lib/document/bin-src/ocr.mjs
|
|
8027
8027
|
var import_promises = require("node:fs/promises");
|
|
8028
|
+
var import_node_path3 = require("node:path");
|
|
8029
|
+
|
|
8030
|
+
// packages/core/dist/document/ocr.js
|
|
8031
|
+
var import_node_fs = require("node:fs");
|
|
8032
|
+
var import_node_path2 = require("node:path");
|
|
8033
|
+
|
|
8034
|
+
// packages/core/dist/fs/paths.js
|
|
8035
|
+
var import_node_os = require("node:os");
|
|
8028
8036
|
var import_node_path = require("node:path");
|
|
8037
|
+
var TALOS_RESERVED_DIR_NAMES = {
|
|
8038
|
+
/** `<profilesRoot>/.bootstrap/` — pre-login installation configuration. */
|
|
8039
|
+
bootstrap: ".bootstrap",
|
|
8040
|
+
/** `bundled/.tmp/` — install staging and vacated installs awaiting cleanup. */
|
|
8041
|
+
installScratch: ".tmp",
|
|
8042
|
+
/** `bundled/.quarantine/` — integrity-failed bundles kept for post-mortem. */
|
|
8043
|
+
quarantine: ".quarantine",
|
|
8044
|
+
/** `data/ose/<id>/sessions/.locks/` — cross-process session ownership locks. */
|
|
8045
|
+
sessionLocks: ".locks"
|
|
8046
|
+
};
|
|
8047
|
+
var TALOS_BOOTSTRAP_DIR_NAME = TALOS_RESERVED_DIR_NAMES.bootstrap;
|
|
8048
|
+
function getTalosOsCacheDir() {
|
|
8049
|
+
if (process.platform === "darwin")
|
|
8050
|
+
return (0, import_node_path.join)((0, import_node_os.homedir)(), "Library", "Caches", "Talos");
|
|
8051
|
+
if (process.platform === "win32") {
|
|
8052
|
+
const local = process.env.LOCALAPPDATA?.trim();
|
|
8053
|
+
return (0, import_node_path.join)(local ? local : (0, import_node_path.join)((0, import_node_os.homedir)(), "AppData", "Local"), "Talos", "Cache");
|
|
8054
|
+
}
|
|
8055
|
+
const xdg = process.env.XDG_CACHE_HOME?.trim();
|
|
8056
|
+
return (0, import_node_path.join)(xdg ? xdg : (0, import_node_path.join)((0, import_node_os.homedir)(), ".cache"), "talos");
|
|
8057
|
+
}
|
|
8029
8058
|
|
|
8030
8059
|
// packages/core/dist/document/ocr.js
|
|
8031
|
-
var LANG_RE = /^[a-z]{3}(\+[a-z]{3})*$/;
|
|
8060
|
+
var LANG_RE = /^[a-z]{3}(_[a-z]+)*(\+[a-z]{3}(_[a-z]+)*)*$/;
|
|
8061
|
+
function isValidOcrLang(lang) {
|
|
8062
|
+
return LANG_RE.test(lang);
|
|
8063
|
+
}
|
|
8064
|
+
function defaultOcrCachePath() {
|
|
8065
|
+
return (0, import_node_path2.join)(getTalosOsCacheDir(), "tessdata");
|
|
8066
|
+
}
|
|
8067
|
+
var CJK = "[\\u2e80-\\u2eff\\u3000-\\u303f\\u3040-\\u30ff\\u3100-\\u312f\\u31a0-\\u31ff\\u3200-\\u33ff\\u3400-\\u4dbf\\u4e00-\\u9fff\\uf900-\\ufaff\\ufe30-\\ufe4f\\uff00-\\uffef]";
|
|
8068
|
+
var CJK_GAP = new RegExp(`(${CJK})[ \\t]+(?=${CJK})`, "g");
|
|
8069
|
+
function tidyCjkSpacing(text) {
|
|
8070
|
+
return text.replace(CJK_GAP, "$1");
|
|
8071
|
+
}
|
|
8072
|
+
var UNSPACED_LANG = /^(chi_|jpn)/;
|
|
8073
|
+
var oneLine = (e) => String(e instanceof Error ? e.message : e).replace(/^Error:\s*/, "").replace(/\s+/g, " ").trim();
|
|
8032
8074
|
async function ocrImage(image, opts = {}) {
|
|
8033
8075
|
if (!image || image.length === 0)
|
|
8034
8076
|
throw new Error("empty image");
|
|
8035
8077
|
const lang = opts.lang ?? "eng";
|
|
8036
|
-
if (!
|
|
8037
|
-
throw new Error(`invalid lang "${lang}" (expected e.g. "eng" or "eng
|
|
8078
|
+
if (!isValidOcrLang(lang))
|
|
8079
|
+
throw new Error(`invalid lang "${lang}" (expected e.g. "eng", "chi_sim" or "chi_sim+eng")`);
|
|
8080
|
+
const langs = lang.split("+");
|
|
8081
|
+
const cachePath = opts.cachePath || defaultOcrCachePath();
|
|
8082
|
+
let langPath = opts.langPath;
|
|
8083
|
+
let cacheMethod;
|
|
8084
|
+
let notBundled = langs;
|
|
8085
|
+
if (!langPath && opts.bundledLangPath) {
|
|
8086
|
+
const bundledDir = opts.bundledLangPath;
|
|
8087
|
+
const packOf = (l) => (0, import_node_path2.join)(bundledDir, `${l}.traineddata.gz`);
|
|
8088
|
+
notBundled = langs.filter((l) => !(0, import_node_fs.existsSync)(packOf(l)));
|
|
8089
|
+
if (notBundled.length === 0) {
|
|
8090
|
+
langPath = bundledDir;
|
|
8091
|
+
cacheMethod = "none";
|
|
8092
|
+
} else {
|
|
8093
|
+
try {
|
|
8094
|
+
(0, import_node_fs.mkdirSync)(cachePath, { recursive: true });
|
|
8095
|
+
for (const l of langs) {
|
|
8096
|
+
const cached = (0, import_node_path2.join)(cachePath, `${l}.traineddata`);
|
|
8097
|
+
if (!notBundled.includes(l) && !(0, import_node_fs.existsSync)(cached))
|
|
8098
|
+
(0, import_node_fs.copyFileSync)(packOf(l), cached);
|
|
8099
|
+
}
|
|
8100
|
+
} catch {
|
|
8101
|
+
}
|
|
8102
|
+
}
|
|
8103
|
+
}
|
|
8104
|
+
if (cacheMethod !== "none") {
|
|
8105
|
+
try {
|
|
8106
|
+
(0, import_node_fs.mkdirSync)(cachePath, { recursive: true });
|
|
8107
|
+
} catch {
|
|
8108
|
+
}
|
|
8109
|
+
}
|
|
8038
8110
|
const mod = await Promise.resolve().then(() => __toESM(require_src(), 1));
|
|
8039
|
-
const
|
|
8040
|
-
if (typeof
|
|
8041
|
-
throw new Error("tesseract.js is unavailable (
|
|
8042
|
-
let
|
|
8111
|
+
const createWorker = mod.createWorker ?? mod.default?.createWorker;
|
|
8112
|
+
if (typeof createWorker !== "function")
|
|
8113
|
+
throw new Error("tesseract.js is unavailable (createWorker not found)");
|
|
8114
|
+
let fail;
|
|
8115
|
+
const failed = new Promise((_, reject) => {
|
|
8116
|
+
fail = reject;
|
|
8117
|
+
});
|
|
8118
|
+
failed.catch(() => void 0);
|
|
8119
|
+
let worker;
|
|
8043
8120
|
try {
|
|
8044
|
-
|
|
8045
|
-
|
|
8046
|
-
|
|
8047
|
-
|
|
8048
|
-
|
|
8121
|
+
worker = await Promise.race([
|
|
8122
|
+
createWorker(lang, 1, {
|
|
8123
|
+
cachePath,
|
|
8124
|
+
...langPath ? { langPath } : {},
|
|
8125
|
+
...cacheMethod ? { cacheMethod } : {},
|
|
8126
|
+
...opts.workerPath ? { workerPath: opts.workerPath } : {},
|
|
8127
|
+
errorHandler: (e) => fail(new Error(oneLine(e)))
|
|
8128
|
+
}),
|
|
8129
|
+
failed
|
|
8130
|
+
]);
|
|
8131
|
+
if (langs.some((l) => UNSPACED_LANG.test(l)))
|
|
8132
|
+
await worker.setParameters({ preserve_interword_spaces: "1" });
|
|
8133
|
+
const result = await Promise.race([worker.recognize(Buffer.from(image)), failed]);
|
|
8134
|
+
return { text: tidyCjkSpacing((result.data.text ?? "").trim()), confidence: result.data.confidence ?? 0 };
|
|
8049
8135
|
} catch (e) {
|
|
8050
|
-
|
|
8136
|
+
const msg = oneLine(e);
|
|
8137
|
+
const which = notBundled.length && !langPath ? ` for ${notBundled.join("+")} (not bundled; downloaded on first use, needs network)` : "";
|
|
8138
|
+
throw new Error(worker ? `OCR failed: ${msg}` : `OCR failed: could not load language data${which}: ${msg}`);
|
|
8139
|
+
} finally {
|
|
8140
|
+
await worker?.terminate().catch(() => void 0);
|
|
8051
8141
|
}
|
|
8052
|
-
return { text: (result.data.text ?? "").trim(), confidence: result.data.confidence ?? 0 };
|
|
8053
8142
|
}
|
|
8054
8143
|
|
|
8055
8144
|
// apps/admin/data/skills.lib/document/bin-src/ocr.mjs
|
|
8145
|
+
process.noDeprecation = true;
|
|
8056
8146
|
function die(msg, code = 1) {
|
|
8057
8147
|
process.stderr.write(`ocr: ${msg}
|
|
8058
8148
|
`);
|
|
@@ -8062,15 +8152,16 @@ var IMG = /* @__PURE__ */ new Set([".png", ".jpg", ".jpeg", ".bmp", ".pbm", ".we
|
|
|
8062
8152
|
async function main() {
|
|
8063
8153
|
const [file, lang] = process.argv.slice(2);
|
|
8064
8154
|
if (!file) die("usage: ocr <image.png|jpg> [lang]", 64);
|
|
8065
|
-
const ext = (0,
|
|
8155
|
+
const ext = (0, import_node_path3.extname)(file).toLowerCase();
|
|
8066
8156
|
if (!IMG.has(ext)) die(`expected an image (${[...IMG].join("/")}); for PDFs render a page first, then OCR`, 64);
|
|
8067
8157
|
const bytes = new Uint8Array(await (0, import_promises.readFile)(file).catch((e) => die(`cannot read ${file}: ${e.message}`)));
|
|
8068
8158
|
const cachePath = process.env.TALOS_TESSDATA || void 0;
|
|
8069
8159
|
const langPath = process.env.TALOS_TESSDATA_LANGPATH || void 0;
|
|
8070
|
-
const workerPath = (0,
|
|
8160
|
+
const workerPath = (0, import_node_path3.join)(__dirname, "ocr-worker.cjs");
|
|
8161
|
+
const bundledLangPath = (0, import_node_path3.join)(__dirname, "..", "assets", "tessdata");
|
|
8071
8162
|
let result;
|
|
8072
8163
|
try {
|
|
8073
|
-
result = await ocrImage(bytes, { lang: lang || "eng", cachePath, langPath, workerPath });
|
|
8164
|
+
result = await ocrImage(bytes, { lang: lang || "eng", cachePath, langPath, bundledLangPath, workerPath });
|
|
8074
8165
|
} catch (e) {
|
|
8075
8166
|
die(e.message);
|
|
8076
8167
|
}
|