-
Notifications
You must be signed in to change notification settings - Fork 4
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
klown
wants to merge
2
commits into
inclusive-design:main
Choose a base branch
from
klown:feat/svg-preview
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.