[TikiWiki-commits] [Git][tikiwiki/tiki][master] [REF] Replace laminas-text with npm figlet
"ushindi bienvenu \(@usbbush\) via TikiWiki-cvs" <[email protected]>
| Newsgroups | gmane.comp.cms.tiki.cvs |
|---|---|
| Message-ID | <688d2c2e652af_2c10ab7c43859f@gitlab-sidekiq-low-urgency-cpu-bound-v2-655597b6c5-qvgcn.mail> |
ushindi bienvenu pushed to branch master at Tiki Wiki CMS Groupware / Tiki
Commits:
8cee4ac4 by ushindi bienvenu at 2025-08-01T20:57:52+00:00
[REF] Replace laminas-text with npm figlet
---
* [REM][NEW] Replace laminas-text with npm figlet
See merge request tikiwiki/tiki!8095
- - - - -
9 changed files:
- lib/wiki-plugins/wikiplugin_figlet.php
- package-lock.json
- package.json
- path_js_importmap_generator.php
- + src/js/tiki-figlet/figlet.js
- + src/js/tiki-figlet/package.json
- src/js/vite.config.mjs
- vendor_bundled/composer.json
- vendor_bundled/composer.lock
Changes:
=====================================
lib/wiki-plugins/wikiplugin_figlet.php
=====================================
@@ -4,8 +4,6 @@
//
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
-use Laminas\Text\Figlet\Figlet;
-
function wikiplugin_figlet_info(): array
{
return [
@@ -19,7 +17,7 @@ function wikiplugin_figlet_info(): array
'body' => tra('Content'),
'params' => [
'font' => [
- 'required' => false,
+ 'required' => true,
'name' => tra('Font face'),
'description' => tra('Path to "fif" font file. Find more fonts here http://www.figlet.org/fontdb.cgi'),
'filter' => 'text',
@@ -29,6 +27,7 @@ function wikiplugin_figlet_info(): array
'name' => tra('Output width'),
'description' => tra('Defines the maximum width of the output string in characters.'),
'filter' => 'int',
+ 'default' => 100,
]
]
];
@@ -39,26 +38,36 @@ function wikiplugin_figlet_info(): array
* @param array $params
*
* @return string html
+ * @throws Exception
*/
-function wikiplugin_figlet(string $data, array $params): string
+function wikiplugin_figlet(string $data, array $params): string | WikiParser_PluginOutput
{
if (empty($data)) {
return '';
}
+ $fontPath = $params['font'] ?? null;
+ $width = $params['width'] ?? 500;
- $string = new Figlet();
- /**
- * @TODO erase the default font
- */
- //If we have a font set up in $params
- if (! empty($params['font'])) {
- $string->setFont($params['font']);
+ if (empty($fontPath)) {
+ return WikiParser_PluginOutput::error(tr('Error'), tr('The %0 parameter is missing', 'font'));
}
- //else keep the default font-face
-
- if (! empty($params['width'])) {
- $string->setOutputWidth($params['width']);
+ if (! is_file($fontPath)) {
+ return WikiParser_PluginOutput::error(tr('Error'), tr('%0 is not a file', $fontPath));
}
-
- return "<pre>" . $string->render($data) . "</pre>";
+ $uniqueId = 'elem_' . uniqid();
+ $jsData = json_encode($data);
+ $jsFontPath = json_encode($fontPath);
+ static $figlet_module_imported = false;
+ $script = '';
+ if (! $figlet_module_imported) {
+ $script .= <<<JS_IMPORT
+import { generateFiglet } from "@tiki-figlet";
+JS_IMPORT;
+ $figlet_module_imported = true;
+ }
+ $script .= <<<JS_CALL
+generateFiglet($jsFontPath, "$width", "$uniqueId", $jsData);
+JS_CALL;
+ TikiLib::lib('header')->add_js_module($script);
+ return "<pre id='$uniqueId'></pre>";
}
=====================================
package-lock.json
=====================================
@@ -16,6 +16,7 @@
"src/js/tiki-html5-qrcode",
"src/js/tiki-mermaid",
"src/js/tiki-sentry-browser",
+ "src/js/tiki-figlet",
"src/js/tiki-iot",
"src/js/tiki-toast-ui",
"src/js/tiki-vue-sfc-loader",
@@ -7519,6 +7520,18 @@
"resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.2.tgz",
"integrity": "sha512-cPJU47OaAoCbg0pBvzsgpTPhmhqI5eJjh/JIu8tPj5q+T7iLvW/JAYUqmE7KOB4R1ZyEhzBaIQpQpardBF5z8A=="
},
+ "node_modules/figlet": {
+ "version": "1.8.2",
+ "resolved": "https://registry.npmjs.org/figlet/-/figlet-1.8.2.tgz",
+ "integrity": "sha512-iPCpE9B/rOcjewIzDnagP9F2eySzGeHReX8WlrZQJkqFBk2wvq8gY0c6U6Hd2y9HnX1LQcYSeP7aEHoPt6sVKQ==",
+ "license": "MIT",
+ "bin": {
+ "figlet": "bin/index.js"
+ },
+ "engines": {
+ "node": ">= 0.4.0"
+ }
+ },
"node_modules/file-entry-cache": {
"version": "8.0.0",
"resolved": "https://registry.npmjs.org/file-entry-cache/-/file-entry-cache-8.0.0.tgz",
@@ -14168,6 +14181,10 @@
"integrity": "sha512-ev2QzSzWPYmy9GuqfIVildA4OdcGLeFZQrq5ys6RtiuF+RQQiZWr8TZNyAcuVXyQRYfEO+MsoB/1BuQVhOJuoQ==",
"dev": true
},
+ "node_modules/tiki-figlet": {
+ "resolved": "src/js/tiki-figlet",
+ "link": true
+ },
"node_modules/tiki-glightbox": {
"resolved": "src/js/tiki-glightbox",
"link": true
@@ -15881,6 +15898,12 @@
"summernote": "^0.9.1"
}
},
+ "src/js/tiki-figlet": {
+ "version": "1.0.0",
+ "dependencies": {
+ "figlet": "^1.8.2"
+ }
+ },
"src/js/tiki-glightbox": {
"version": "1.0.0",
"license": "ISC",
=====================================
package.json
=====================================
@@ -114,6 +114,7 @@
"src/js/tiki-html5-qrcode",
"src/js/tiki-mermaid",
"src/js/tiki-sentry-browser",
+ "src/js/tiki-figlet",
"src/js/tiki-iot",
"src/js/tiki-toast-ui",
"src/js/tiki-vue-sfc-loader",
=====================================
path_js_importmap_generator.php
=====================================
@@ -76,6 +76,7 @@ function generateJsImportmapScripts(bool $useBaseUrl = false)
"@tiki-modules/sentryBrowser" => $tikiUrl . JS_ASSETS_PATH . "/tiki-sentry-browser.js",
"@mermaidPack" => $tikiUrl . JS_ASSETS_PATH . "/tiki-mermaid.js",
"@tiki-glightbox" => $tikiUrl . JS_ASSETS_PATH . "/tiki-glightbox.js",
+ "@tiki-figlet" => $tikiUrl . JS_ASSETS_PATH . "/tiki-figlet.js",
/* Toast-ui editor */
"@tiki-toast-ui/editor-index" => $tikiUrl . JS_ASSETS_PATH . "/tiki-toast-ui.js",
=====================================
src/js/tiki-figlet/figlet.js
=====================================
@@ -0,0 +1,42 @@
+import figlet from "figlet";
+export async function generateFiglet(path, width, domElId, text) {
+ const filename = getFilename(path);
+ let fontName = null;
+ async function loadFont(fontName) {
+ const res = await fetch(path);
+ if (!res.ok) {
+ throw new Error(tr("An error occurred while fetching the font"));
+ }
+ const fontData = await res.text();
+ figlet.parseFont(fontName, fontData);
+ }
+
+ function getFilename(path) {
+ // Handle both forward and backward slashes
+ const parts = path.split(/[/\\]/);
+ return parts.pop(); // Get the last element (filename)
+ }
+
+ if (filename.endsWith(".flf")) {
+ fontName = filename.replace(".flf", "");
+ try {
+ await loadFont(fontName);
+ } catch (e) {
+ document.getElementById(domElId).textContent = tr("Error loading font");
+ return;
+ }
+ }
+
+ figlet.text(text, { font: fontName, width: width }, function (err, data) {
+ const targetElement = document.getElementById(domElId);
+ if (err) {
+ if (targetElement) {
+ targetElement.textContent = tr("Error generating text");
+ }
+ return;
+ }
+ if (targetElement) {
+ targetElement.textContent = data;
+ }
+ });
+}
=====================================
src/js/tiki-figlet/package.json
=====================================
@@ -0,0 +1,17 @@
+{
+ "name" : "tiki-figlet",
+ "version" : "1.0.0",
+ "description" : "",
+ "main" : "index.js",
+ "scripts" : {
+ "test" : "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository" : {
+ "type" : "git",
+ "url" : "https://gitlab.com/tikiwiki/tiki.git"
+ },
+ "private" : true,
+ "dependencies": {
+ "figlet": "^1.8.2"
+ }
+}
=====================================
src/js/vite.config.mjs
=====================================
@@ -123,6 +123,7 @@ export default defineConfig(({ command, mode }) => {
"root-config": resolve(__dirname, "vue-mf/root-config/src/root-config.js"),
"tiki-glightbox": resolve(__dirname, "tiki-glightbox/glightbox-index.js"),
"tiki-sentry-browser": resolve(__dirname, "tiki-sentry-browser/sentry-browser.js"),
+ "tiki-figlet": resolve(__dirname, "tiki-figlet/figlet.js"),
styleguide: resolve(__dirname, "vue-mf/styleguide/src/styleguide.js"),
"tiki-offline": resolve(__dirname, "vue-mf/tiki-offline/src/tiki-offline.js"),
"toolbar-dialogs": resolve(__dirname, "vue-mf/toolbar-dialogs/src/toolbar-dialogs.js"),
=====================================
vendor_bundled/composer.json
=====================================
@@ -218,7 +218,6 @@
"laminas/laminas-session": "~2.9",
"laminas/laminas-soap": "~2.8",
"laminas/laminas-tag": "~2.7",
- "laminas/laminas-text": "~2.8",
"laminas/laminas-uri": "~2.9",
"laminas/laminas-validator": "~2.13",
"league/commonmark": "~2.6",
=====================================
vendor_bundled/composer.lock
=====================================
@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "648ed4203d0c784ec09b57fd17c008f9",
+ "content-hash": "f487de78748613bca80261d7961817e5",
"packages": [
{
"name": "amphp/amp",
@@ -15535,16 +15535,16 @@
},
{
"name": "myclabs/deep-copy",
- "version": "1.13.3",
+ "version": "1.13.4",
"source": {
"type": "git",
"url": "https://github.com/myclabs/DeepCopy.git",
- "reference": "faed855a7b5f4d4637717c2b3863e277116beb36"
+ "reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/faed855a7b5f4d4637717c2b3863e277116beb36",
- "reference": "faed855a7b5f4d4637717c2b3863e277116beb36",
+ "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/07d290f0c47959fd5eed98c95ee5602db07e0b6a",
+ "reference": "07d290f0c47959fd5eed98c95ee5602db07e0b6a",
"shasum": ""
},
"require": {
@@ -15583,7 +15583,7 @@
],
"support": {
"issues": "https://github.com/myclabs/DeepCopy/issues",
- "source": "https://github.com/myclabs/DeepCopy/tree/1.13.3"
+ "source": "https://github.com/myclabs/DeepCopy/tree/1.13.4"
},
"funding": [
{
@@ -15591,7 +15591,7 @@
"type": "tidelift"
}
],
- "time": "2025-07-05T12:25:42+00:00"
+ "time": "2025-08-01T08:46:24+00:00"
},
{
"name": "nikic/php-parser",
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/8cee4ac49e5d31258cb61a97018fed0d6836365b
--
View it on GitLab: https://gitlab.com/tikiwiki/tiki/-/commit/8cee4ac49e5d31258cb61a97018fed0d6836365b
You're receiving this email because of your account on gitlab.com.
_______________________________________________
TikiWiki-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tikiwiki-cvs