Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: web app for previewing svg markup returned by BlissSVGBuilder #22

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions apps/svg-preview/svg-preview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<html>
<head>
<title>Bliss SVG Previewer</title>
<style>
svg {
border: 2px solid gray;
background: GhostWhite;
}
</style>
</head>
<body>
<script type="module">
import "./svg-preview.ts";
</script>
<h1>Bliss SVG Previewer</h1>
<p>
The encoding string entered below is a space separated sequence of BCI-AV
identfiers and separators such as "/" and ";". The sequence can be as
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be helpful to explain what "/" and ";" mean. Something like:

  • In the format of [12335, "/", 8499], the Bliss character 12335 and the Bliss character of 8499 are displayed side by side
  • In the format of [12335, ";", 8499], the Bliss character 12335 and the indicator 8499 are displayed in the way that the indicator 8499 is on top of the the charactor 12355

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. However, in exploring the Bliss SVG builder for more information, I discovered that this string will work as well: "HC8N:0,8;S4:2,10". It is used by the BMW palette for the first part of "Abs. Time", the "Abs." part.

That means that the legitimate encodings can be complicated and use letters, colons, and commas as well as slash and semi-colon. I have adjusted the code to take that all into account.

However, I can't find any documentation for the structure of these encodings. Do you know if there is any?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know about the documentation. Hannes will know better.

simple as a single BCI-AV identifier.
<p>
<label for="bciAvIdType">Encoding:</label><br>
<input type="text" id="bciAvIdType" size="40">
</p>
<p>
<button id="preview">Preview</button>
</p>
<p>
<p>Symbol will be displayed below:</p>
<p id="display"></p>
</body>
</html>
72 changes: 72 additions & 0 deletions apps/svg-preview/svg-preview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2024 Inclusive Design Research Centre, OCAD University
* All rights reserved.
*
* Licensed under the New BSD license. You may not use this file except in
* compliance with this License.
*
* You may obtain a copy of the License at
* https://github.com/inclusive-design/adaptive-palette/blob/main/LICENSE
*/

import { initAdaptivePaletteGlobals } from "../../src/client/GlobalData";
import { getSvgElement } from "../../src/client/SvgUtils";

// Initialize any globals used elsewhere in the code.
await initAdaptivePaletteGlobals("mainPaletteDisplayArea");

const encodingInputElement = document.getElementById("bciAvIdType");
const displayElement = document.getElementById("display");
const undefinedSpanEl = document.createElement("span");
undefinedSpanEl.innerText = "One or more BCI-AV-IDs are not valid";

/**
* Given the encoding string for a Bliss character or word, get the SVG markup
* for it, and then add it to the preview area. Note that the encoding string
* is either a single BCi-AV identifier or a space separated sequence of BCi-AV
* identifier and "/" or ";"
*/
function getAndDisplayBliss () {
const inputString = encodingInputElement.value;
let blissSvgEl;

displayElement.innerText = ""; // clear the display area
if (inputString.trim() === "") {
displayElement.innerText = "Please input an encoding";
}
else {
const encodingArray = inputString
.replace(/["']/g,"") // remove all quotation marks
.replace(/\s\s+/g, " ") // reduce all whitespace to a single space
.split(" "); // create an array of strings
// Loop to remove any trailing commas from a string in the array, and to
// convert all the number strings into integers, e.g., "5" => 5.
// Regarding `parseInt()/isNaN()`: any item that is a number or number-like
// is not `NaN`, but punctuation is. For example, the string "5" and the
// number 5 both parse to a numeric value, but "/" is parsed to `NaN`.
encodingArray.forEach( (item, index, array) => {
item = item.replace(/,+$/, ""); // remove any trailing commas
const value = parseInt(item);
if (isNaN(value)) {
array[index] = item;
}
else {
array[index] = value;
}
});
console.debug(encodingArray);
blissSvgEl = getSvgElement(encodingArray) || undefinedSpanEl;

// If the `displayElement` has a child from a previous run, replace it with
// the latest result, otherwise add a new child.
const childToReplace = displayElement.children[0];
if (childToReplace) {
displayElement.replaceChild(blissSvgEl, childToReplace);
}
else {
displayElement.appendChild(blissSvgEl);
}
}
}

document.getElementById("preview").addEventListener("click", getAndDisplayBliss);
Loading