Members
(constant) ALLOW_REDUNDANT_ALL :boolean
Flag to allow an "All" option in filters to make it easy to return to a
default state.
Type:
- boolean
- Source:
(constant) ALLOW_SCORE_DISPLAY :boolean
Flag to indicate if large score displays are active.
Type:
- boolean
- Source:
(constant) ALWAYS_ON_STREAMS :Array.<string>
Stream types that are always available regardless of substance configuration.
Type:
- Array.<string>
- Source:
(constant) AUTORUN_WAIT
Presenter class for handling code editor functionality.
- License:
- BSD
- Source:
(constant) BOOLEAN_VALUES
Boolean value mapping for CSV parsing.
Maps various string representations to boolean values.
Throws exception if value not found in either true or false sets.
- Source:
(constant) COLORS :Array.<string>
Array of colors used for visualizations
Type:
- Array.<string>
- Source:
(constant) COMMAND_COMPATIBILITIES :Object.<string, string>
Command compatibility mapping to compatibility modes:
- "any": Compatible with both policy and definition contexts
- "none": Not compatible with simplified UI
- "definition": Only compatible with substance definitions.
- "policy": Only compatible with policy modifications.
Type:
- Object.<string, string>
- Source:
(constant) DEFAULT_CORES :number
Default number of CPU cores to assume when hardwareConcurrency is unavailable.
Type:
- number
- Source:
(constant) DEFAULT_SALES_TO_ASSUME_MODE
Mapping from CSV defaultSales values to internal assumeMode values.
Supports both user-facing values (from exports) and internal values (backward compatibility).
Used during CSV import to normalize defaultSales to internal representation.
- Source:
(constant) ENABLEABLE_STREAMS :Array.<string>
Stream types that can be enabled/disabled based on substance configuration.
Type:
- Array.<string>
- Source:
(constant) ENFORCE_SCENARIO_CONSTRAINT :boolean
Flag to enforce scenario selection when dimension is not simulations.
This constraint prevents displaying all scenarios simultaneously with a
non-scenario dimension, which would create difficult to interpret charts.
Type:
- boolean
- Source:
(constant) GLOBAL_CONTEXT
Constants used across the tool.
- License:
- BSD, see LICENSE.md.
- Source:
(constant) META_COLUMNS
Standard CSV column order for substance metadata export/import.
Used consistently across serialization and deserialization operations.
- Source:
(constant) NUMERIC_INPUT_INVALID_PATTERNS :Array.<RegExp>
Invalid patterns for numeric input validation.
Type:
- Array.<RegExp>
- Source:
(constant) OBJ_IDENTIFIER_REGEX
Regular expression for matching consumption/policy object identifiers.
Matches format: "substance" for "application"
- Source:
(constant) RESOLVED_FULL_NAME_REGEX
Regular expression for matching resolved substance names with optional suffix.
Matches format: "substance" for "application" (optional suffix)
- Source:
(constant) STREAM_TARGET_SELECTORS :Array.<string>
Stream target selectors used throughout the application for updating dropdown states.
Type:
- Array.<string>
- Source:
(constant) TIMEOUT_PER_SCENARIO :number
Timeout in milliseconds per scenario for simulation execution.
Type:
- number
- Source:
(constant) UNIT_VALUE_EXAMPLES
Examples of unit value formats for parsing.
- Source:
(constant) UNIT_VALUE_REGEX
Regex for parsing unit values with numeric component and units.
Matches: optional sign, digits with optional commas, optional decimal,
optional %, space, non-whitespace units
- Source:
(constant) UNIT_VALUE_REGEX_FULL
Regex for matching number with optional commas, decimals, and % followed by units.
- Source:
(constant) VALID_DEFAULT_SALES_VALUES
Valid defaultSales values for error reporting.
Ordered: user-facing values first, then internal values.
- Source:
(constant) VALID_YEAR_KEYWORDS :Array.<string>
Valid QubecTalk year keywords that should not trigger validation warnings.
Type:
- Array.<string>
- Source:
wasmLayer
WASM web worker for executing QubecTalk simulations using Java backend.
This worker provides the same interface as legacy.worker.js but uses
the Java-based QubecTalk interpreter compiled to WASM with JS fallback
for legacy browser support.
- License:
- BSD, see LICENSE.md.
- Source:
Methods
alertWithHelpOption(message)
Show the user an alert and offer help.
Show the user an alert to the user with the given message as a confirm
dialog. HELP_TEXT will be added to the end. If the user says OK, then
they will be redirected to /guide/get_help.html
Parameters:
| Name | Type | Description |
|---|---|---|
message |
string | The message to display. |
buildAddCode(target) → {function}
Create a function that adds indented code pieces to a target array.
Parameters:
| Name | Type | Description |
|---|---|---|
target |
Array.<string> | Target array to add code pieces to |
- Source:
Returns:
Function that takes a code piece and spaces count
- Type
- function
buildSetupListButton(postCallback)
Build a function which sets up a list button with add/delete functionality.
Parameters:
| Name | Type | Description |
|---|---|---|
postCallback |
function | Function to call after each list item UI is initialized or removed. If not given, will use a no-op. |
- Source:
buildUpdateCount(dialog)
Build a function which updates displays of command counts.
Parameters:
| Name | Type | Description |
|---|---|---|
dialog |
Selection over the dialog in which the command count displays should be updated. |
- Source:
Returns:
Funciton which takes a string list selector and a string display
selector. That function will put the count of commands found in the
list selector into the display selector.
captureSentryMessage()
Send a report of an issue to Sentry if enabled.
(async) executeCode(code, scenarioName) → {Promise.<string>}
Execute QubecTalk code using WASM backend.
Parameters:
| Name | Type | Description |
|---|---|---|
code |
string | The QubecTalk code to execute. |
scenarioName |
string | Scenario name to execute, or empty string for all scenarios. |
- Source:
Returns:
Promise resolving to status + CSV results.
- Type
- Promise.<string>
finalizeCodePieces(target) → {string}
Join code pieces into a single string with newlines.
Parameters:
| Name | Type | Description |
|---|---|---|
target |
Array.<string> | Array of code pieces to join |
- Source:
Returns:
Combined code string
- Type
- string
formatEngineNumber(engineNumber) → {string}
Formats an EngineNumber for code generation, preserving original string when available.
Parameters:
| Name | Type | Description |
|---|---|---|
engineNumber |
EngineNumber | The EngineNumber to format. |
- Source:
Returns:
Formatted string with value and units.
- Type
- string
getBaseName(fullName) → {string}
Extract base application/substance name by removing subtype suffix.
For "Refrigeration - Commercial", returns "Refrigeration".
For "HFC-134a", returns "HFC-134a" (no change).
Parameters:
| Name | Type | Description |
|---|---|---|
fullName |
string | Full name with potential subtype. |
- Source:
Returns:
Base name without subtype.
- Type
- string
getColor(i) → {string}
Get a color from the predefined color palette.
Parameters:
| Name | Type | Description |
|---|---|---|
i |
number | Index into color array. |
- Source:
Returns:
Color hex code.
- Type
- string
getEngineNumberValue(valSelection, unitsSelection) → {EngineNumber}
Gets an engine number from value/units form fields.
Parameters:
| Name | Type | Description |
|---|---|---|
valSelection |
HTMLElement | Value input element. |
unitsSelection |
HTMLElement | Units select element. |
- Source:
Returns:
Combined engine number object.
- Type
- EngineNumber
getFieldValue(selection) → {string}
Gets raw value from a form field.
Parameters:
| Name | Type | Description |
|---|---|---|
selection |
HTMLElement | Form field to get value from. |
- Source:
Returns:
The field's value.
- Type
- string
getIsDurationField(input) → {boolean}
Determines if an input element is a duration field.
Parameters:
| Name | Type | Description |
|---|---|---|
input |
HTMLElement | The input element to check. |
- Source:
Returns:
True if the input is a duration field.
- Type
- boolean
getListInput(selection, itemReadStrategy) → {Array}
Read the current items in a list.
Parameters:
| Name | Type | Description |
|---|---|---|
selection |
HTMLElement | The HTML element containing list items. |
itemReadStrategy |
function | A function to process each list item. |
- Source:
Returns:
An array of processed items returned by the strategy.
- Type
- Array
getNumericInputSuggestionAndDescription(fieldDescription, value, isAmbiguous, isParseError, parseResult, numberParser) → {Object}
Gets suggestion and description for numeric input validation.
Parameters:
| Name | Type | Description |
|---|---|---|
fieldDescription |
string | The field description from aria-label. |
value |
string | The input value being validated. |
isAmbiguous |
boolean | Whether the value has an ambiguous format. |
isParseError |
boolean | Whether the value failed to parse. |
parseResult |
Object | The parse result object (if parse error). |
numberParser |
NumberParseUtil | The number parser utility. |
- Source:
Returns:
Object with suggestion and description fields.
- Type
- Object
getSanitizedFieldValue(selection) → {string}
Gets sanitized value from a form field, removing quotes and commas.
Parameters:
| Name | Type | Description |
|---|---|---|
selection |
HTMLElement | Form field to get sanitized value from. |
- Source:
Returns:
Sanitized field value.
- Type
- string
getWithMetaApplications(applicationNamesRaw)
Add references to application metagroups.
Add references to application metagroups by looking for those with subgroups
(subapplications) and adding an "- All" option which can be used to filter
for all subapplications within the application.
Parameters:
| Name | Type | Description |
|---|---|---|
applicationNamesRaw |
Array | Iterable of string application names. |
- Source:
getWithMetaEquipment(applicationNamesRaw)
Adds equipment model meta-options to application names.
Creates "Application - All" options for applications that have
equipment models, similar to how getWithMetaApplications works for subapplications.
Parameters:
| Name | Type | Description |
|---|---|---|
applicationNamesRaw |
Array | Iterable of string application names. |
- Source:
getWithMetaSubstanceEquipment(substanceNamesRaw)
Adds equipment model meta-options to substance names.
Creates "Substance - All" options for substances that have
equipment models, similar to how getWithMetaApplications works for subapplications.
Parameters:
| Name | Type | Description |
|---|---|---|
substanceNamesRaw |
Array | Iterable of string substance names. |
- Source:
indent(pieces, spaces) → {Array.<string>}
Indent an array of text pieces by the specified number of spaces.
Parameters:
| Name | Type | Description |
|---|---|---|
pieces |
Array.<string> | Array of text pieces to indent |
spaces |
number | Number of spaces to indent each piece |
- Source:
Returns:
Array of indented text pieces
- Type
- Array.<string>
indentSingle(piece, spaces) → {string}
Indent a single piece of text by the specified number of spaces.
Parameters:
| Name | Type | Description |
|---|---|---|
piece |
string | The text to indent |
spaces |
number | Number of spaces to indent. Defaults to 0. |
- Source:
Returns:
The indented text
- Type
- string
initChangeCommandUi(itemObj, root, codeObj, context, streamUpdater)
Initializes a change command UI element.
Parameters:
| Name | Type | Description |
|---|---|---|
itemObj |
Object | The command object to initialize from. |
root |
HTMLElement | The root element containing the UI. |
codeObj |
Object | Optional code object containing substances data. |
context |
string | Context for stream detection ('consumption' or 'policy'). |
streamUpdater |
Object | StreamSelectionAvailabilityUpdater instance. |
- Source:
initLimitCommandUi(itemObj, root, codeObj, context, streamUpdater)
Initializes a limit command UI widget.
Parameters:
| Name | Type | Description |
|---|---|---|
itemObj |
Object | The command object to initialize from. |
root |
HTMLElement | The root element containing the UI. |
codeObj |
Object | The code object containing available substances. |
context |
string | Context for stream detection ('consumption' or 'policy'). |
streamUpdater |
Object | StreamSelectionAvailabilityUpdater instance. |
- Source:
initRechargeCommandUi(itemObj, root, codeObj)
Initializes a recharge command UI widget.
Parameters:
| Name | Type | Description |
|---|---|---|
itemObj |
Object | The recharge command object or null for new commands. |
root |
HTMLElement | The root element containing the UI. |
codeObj |
Object | The code object for context. |
- Source:
initRecycleCommandUi(itemObj, root, codeObj, context, streamUpdater)
Initializes a recycle command UI widget.
Parameters:
| Name | Type | Description |
|---|---|---|
itemObj |
Object | The command object to initialize from. |
root |
HTMLElement | The root element containing the UI. |
codeObj |
Object | Optional code object containing substances data. |
context |
string | Context for stream detection ('consumption' or 'policy'). |
streamUpdater |
Object | StreamSelectionAvailabilityUpdater instance. |
- Source:
initReplaceCommandUi(itemObj, root, codeObj, context, streamUpdater)
Initializes a replace command UI widget.
Parameters:
| Name | Type | Description |
|---|---|---|
itemObj |
Object | The command object to initialize from. |
root |
HTMLElement | The root element containing the UI. |
codeObj |
Object | The code object containing available substances. |
context |
string | Context for stream detection ('consumption' or 'policy'). |
streamUpdater |
Object | StreamSelectionAvailabilityUpdater instance. |
- Source:
initSetCommandUi(itemObj, root, codeObj, context, streamUpdater)
Initializes a set command UI element.
Parameters:
| Name | Type | Description |
|---|---|---|
itemObj |
Object | The command object to initialize from. |
root |
HTMLElement | The root element containing the UI. |
codeObj |
Object | Optional code object containing substances data. |
context |
string | Context for stream detection ('consumption' or 'policy'). |
streamUpdater |
Object | StreamSelectionAvailabilityUpdater instance. |
- Source:
invertNumberString(numberString) → {string}
Inverts the sign of a number string while preserving formatting.
Parameters:
| Name | Type | Description |
|---|---|---|
numberString |
string | The number string to invert |
- Source:
Returns:
The number string with inverted sign
- Type
- string
main()
Main entry point for the application.
makeNumberUnambiguousString(numericValue) → {string}
Converts a numeric value to an unambiguous US-format string.
Ensures numbers are formatted to avoid ambiguity (e.g., 1.234 becomes
"1.2340", 1234 becomes "1,234.0"). Used when we need to generate
formatted strings but don't have access to the user's original
formatting.
Parameters:
| Name | Type | Description |
|---|---|---|
numericValue |
number | The numeric value to format |
- Source:
Returns:
The unambiguous US-format number string
- Type
- string
parseUnitValue(valueString, throwOnError) → {EngineNumber|null}
Parse unit value strings like "5 kgCO2e / kg" into EngineNumber instances.
Handles numeric values with optional commas, decimals, and percentage signs.
Parameters:
| Name | Type | Default | Description |
|---|---|---|---|
valueString |
string | String containing numeric value and units (e.g., "1430 kgCO2e / kg", "10% / year") | |
throwOnError |
boolean | false | Whether to throw errors for invalid formats (default: false) |
- Source:
Returns:
Parsed EngineNumber instance, or null if invalid/empty
- Type
- EngineNumber | null
preprocessEachYearSyntax(input) → {string}
Preprocesses "each year" syntax in input code.
Removes unsupported "each years?" syntax from the end of statements.
Note: Complex year range syntax like "2025 to 2035" is handled differently
and not preprocessed here - see implementation comments for details.
Parameters:
| Name | Type | Description |
|---|---|---|
input |
string | The raw QubecTalk code |
- Source:
Returns:
The preprocessed QubecTalk code
- Type
- string
readChangeCommandUi(root) → {Command}
Reads values from a change command UI element.
Parameters:
| Name | Type | Description |
|---|---|---|
root |
HTMLElement | The root element containing the UI. |
- Source:
Returns:
A new Command object with the UI values.
- Type
- Command
readDurationUi(root) → {YearMatcher}
Reads duration values from a duration UI widget.
Parameters:
| Name | Type | Description |
|---|---|---|
root |
HTMLElement | The root element containing the UI. |
- Source:
Returns:
A new YearMatcher object with the UI values.
- Type
- YearMatcher
readLimitCommandUi(root) → {LimitCommand}
Reads values from a limit command UI widget.
Parameters:
| Name | Type | Description |
|---|---|---|
root |
HTMLElement | The root element containing the UI. |
- Source:
Returns:
A new LimitCommand object with the UI values.
- Type
- LimitCommand
readRechargeCommandUi(root) → {RechargeCommand}
Reads values from a recharge command UI widget.
Parameters:
| Name | Type | Description |
|---|---|---|
root |
HTMLElement | The root element containing the UI. |
- Source:
Returns:
A new RechargeCommand object with the UI values.
- Type
- RechargeCommand
readRecycleCommandUi(root) → {Command}
Reads values from a recycle command UI widget.
Parameters:
| Name | Type | Description |
|---|---|---|
root |
HTMLElement | The root element containing the UI. |
- Source:
Returns:
A new Command object with the UI values.
- Type
- Command
readReplaceCommandUi(root) → {ReplaceCommand}
Reads values from a replace command UI widget.
Parameters:
| Name | Type | Description |
|---|---|---|
root |
HTMLElement | The root element containing the UI. |
- Source:
Returns:
A new ReplaceCommand object with the UI values.
- Type
- ReplaceCommand
readSetCommandUi(root) → {Command}
Reads values from a set command UI element.
Parameters:
| Name | Type | Description |
|---|---|---|
root |
HTMLElement | The root element containing the UI. |
- Source:
Returns:
A new Command object with the UI values.
- Type
- Command
(async) registerServiceWorker()
Simple service worker load script.
See https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API/Using_Service_Workers
Adapted from Global Plastics AI Policy Tool by Josh (https://joshsim.org/)
and the Global Plastics AI Policy Tool (https://global-plastics-tool.org/)
Original under BSD-3-Clause license.
- License:
- BSD
- Source:
reportProgress(progress)
Global reportProgress function called by WASM to report simulation progress.
This function is available globally for the Java code to call via @JSBody.
Parameters:
| Name | Type | Description |
|---|---|---|
progress |
number | Progress value between 0.0 and 1.0 |
- Source:
resolveNameConflict(baseName, existingNames) → {NameConflictResolution}
Resolves name conflicts by appending incrementing numbers until finding a unique name.
Parameters:
| Name | Type | Description |
|---|---|---|
baseName |
string | The initial desired name. |
existingNames |
Set.<string> | Set of existing names to avoid conflicts with. |
- Source:
Returns:
A resolution object with the result.
resolveSubstanceNameConflict(baseName, existingNames) → {NameConflictResolution}
Resolves substance name conflicts with special handling for effective substance names.
This function handles the combination of substance and equipment model names.
Parameters:
| Name | Type | Description |
|---|---|---|
baseName |
string | The initial desired substance name. |
existingNames |
Set.<string> | Set of existing substance names to avoid conflicts with. |
- Source:
Returns:
A resolution object with the result.
setDuring(selection, command, defaultVal, initListeners)
Sets the state of a duration selection UI widget.
Set the duration for shown within a duration selection UI widget to match
that of a given command. If the command is null, it uses the default value.
Parameters:
| Name | Type | Description |
|---|---|---|
selection |
HTMLElement | The selection element containing duration-related inputs. |
command |
Object | The command object from which the duration is extracted. |
defaultVal |
YearMatcher | The default duration value if the command is null. |
initListeners |
boolean | Flag indicating if new event listeners for element visibility should be added in response to changing duration type. |
- Source:
setEngineNumberValue(valSelection, unitsSelection, source, defaultValue, strategy)
Sets a value/units pair for engine number inputs.
Parameters:
| Name | Type | Description |
|---|---|---|
valSelection |
HTMLElement | Value input element. |
unitsSelection |
HTMLElement | Units select element. |
source |
Object | Source object for values. |
defaultValue |
EngineNumber | Default engine number. |
strategy |
function | Function to extract engine number from source. |
- Source:
setFieldValue(selection, source, defaultValue, strategy)
Sets a form field value with fallback to default.
Parameters:
| Name | Type | Description |
|---|---|---|
selection |
HTMLElement | Form field element. |
source |
Object | Source object to get value from. |
defaultValue |
* | Default value if source is null. |
strategy |
function | Function to extract value from source. |
- Source:
setListInput(listSelection, itemTemplate, items, uiInit, removeCallback)
Sets up a list input with template-based items.
Parameters:
| Name | Type | Description |
|---|---|---|
listSelection |
HTMLElement | Container element for list. |
itemTemplate |
string | HTML template for list items. |
items |
Array | Array of items to populate list. |
uiInit |
function | Callback to initialize each item's UI. |
removeCallback |
function | Callback to invoke if item removed. |
- Source:
setupDialogInternalLinks(root, tabs)
Sets up event listeners for internal dialog links.
This function adds click event listeners to dialog internal links that, when
clicked, will toggle the corresponding tab based on the link's href.
Parameters:
| Name | Type | Description |
|---|---|---|
root |
HTMLElement | The root element containing dialog. |
tabs |
Object | Tabby object for managing tab toggling. |
- Source:
setupDurationSelector(newDiv)
Initializes a duration selector.
Parameters:
| Name | Type | Description |
|---|---|---|
newDiv |
HTMLElement | The new element to set up duration selector for. |
- Source:
updateDurationSelector(dateSelector)
Updates the visibility of selector elements based on selected duration type.
Parameters:
| Name | Type | Description |
|---|---|---|
dateSelector |
HTMLElement | The date selector element to update. |
- Source:
validateInductionInput(rawValue) → {string|EngineNumber}
Validates and normalizes induction input values.
Parameters:
| Name | Type | Description |
|---|---|---|
rawValue |
string | The raw input value |
- Source:
Returns:
Normalized induction value
- Type
- string | EngineNumber
validateNumericInputs(dialog, dialogType) → {boolean}
Validates numeric inputs within a dialog and prompts user for potentially
invalid values.
Parameters:
| Name | Type | Description |
|---|---|---|
dialog |
HTMLElement | The dialog element containing numeric inputs |
dialogType |
string | Type of dialog for error message context ("substance", "policy", "simulation") |
- Source:
Returns:
True if user confirms to proceed, false if user cancels
- Type
- boolean