Options
All
  • Public
  • Public/Protected
  • All
Menu

External module "wed/util"

Index

Variables

Const ENCODED_RE

ENCODED_RE: RegExp = /^(?:x[a-f0-9]+)+$/

Const OP_RE

OP_RE: RegExp = /^(?:p([xa-f0-9]+))|(?:[gmu](\d+))/

Let nextID

nextID: number = 0

Functions

_exceptionStackTrace

  • _exceptionStackTrace(err: any): string

anySpecialKeyHeld

  • anySpecialKeyHeld(ev: Event): boolean
  • Parameters

    • ev: Event

      A DOM event.

    Returns boolean

    true if Control, Alt or Meta were held when the event was created. Otherwise, false.

classFromOriginalName

  • classFromOriginalName(name: string, namespaces: Record<string, string>): string
  • Makes a class string for a node in wed's data tree. The string is meant to be used for the corresponding node in wed's GUI tree.

    Parameters

    • name: string

      The original element name.

    • namespaces: Record<string, string>

      The namespaces that are known. This is used to convert element name prefixes to namespace URIs.

    Returns string

    The class string.

Private codeSequenceToString

  • codeSequenceToString(str: string): string
  • Convert a code sequence created with stringToCodeSequence to a string.

    This is meant to be used by wed's internal code.

    Parameters

    • str: string

      The sequence to decode.

    Returns string

    The decoded string.

convertPatternObj

  • convertPatternObj(obj: any, resolver: any): string
  • Convert a "pattern object" to a string that can be shown to the user. This function is meant to be used for "complex" name patterns that we may get from salve. Note that a "pattern object" is the result of calling toObject() on the pattern. The goal of this function is to convert the pattern object to a string that would be interpretable by the end user.

    An explanation about how this handles namespaces and wildcard patterns is in order. In a Relax NG schema the name pattern * in the compact notation is equivalent to <anyName/> in the expanded notation. And foo:* is equivalent to <nsName ns="uri_of_foo"> where uri_of_foo is the URI that has been associated with foo in the compact schema. It would be nice if the function here could reuse this notation, but we cannot. Consider the case where an Relax NG schema in the compact notation wants to declare a name pattern which means "any name in the default namespace". In XML we express a name in the default namespace currently in effect by simply not prefixing it with a namespace name: whereas foo:bar is the bar element in the foo namespace, bar is the bar element in the default namespace. The pattern "any element in namespace foo" is represented with foo:*, however we cannot use * to mean "any element in the default namespace", because * means "any name in any namespace whatsoever". The compact notation forces the author of the schema to use a prefix for the default namespace. And because of this, * means unambiguously "any element in any namespace".

    So the * in the Relax NG schema becomes *:* here. "Any element in the default namespace" is represented by *. Thus foo:* and * can stand in the same relation to one another as foo:bar and bar.

    Parameters

    • obj: any

      The "pattern object" to convert.

    • resolver: any

      The resolver to use to convert URIs to prefixes.

    Returns string

    The string representing the pattern.

decodeAttrName

  • decodeAttrName(encoded: string): object
  • Transforms an attribute name from wed's data tree to the original attribute name before the data was transformed for use with wed. This reverses the transformation done with encodeAttrName.

    Parameters

    • encoded: string

      The encoded name.

    Returns object

    A structure containing the decoded name the optional qualifier.

    • name: string
    • qualifier: string | undefined

Private decodeDiff

  • decodeDiff(name: string, diff: string): string
  • Decode the diff produced with encodeDiff.

    This is meant to be used by wed's internal code.

    Parameters

    • name: string

      The name, after encoding.

    • diff: string

      The diff.

    Returns string

    The decoded attribute name.

distFromDeltas

  • distFromDeltas(delta1: number, delta2: number): number
  • Calculates the distance on the basis of two deltas. This would typically be called with the difference of X coordinates and the difference of Y coordinates.

    Parameters

    • delta1: number

      The first delta.

    • delta2: number

      The second delta.

    Returns number

    The distance.

distFromRect

  • distFromRect(x: number, y: number, left: number, top: number, right: number, bottom: number): number
  • Measures the distance of a point from a rectangle. If the point is in the rectangle or touches it, the distance is 0. In the nomenclature below, left and right are on the X axis and top and bottom on the Y axis.

    Parameters

    • x: number

      The x coordinate of the point.

    • y: number

      The y coordinate of the point.

    • left: number

      The left coordinate of the rectangle.

    • top: number

      The top coordinate of the rectangle.

    • right: number

      The right coordinate of the rectangle.

    • bottom: number

      The bottom coordinate of the rectangle.

    Returns number

    The distance.

distsFromRect

  • distsFromRect(x: number, y: number, left: number, top: number, right: number, bottom: number): object
  • Measures the absolute horizontal and vertical distances of a point from a rectangle. If the point is in the rectangle or touches it, the distance is

    1. In the nomenclature below, left and right are on the X axis and top and bottom on the Y axis.

    Parameters

    • x: number

      The x coordinate of the point.

    • y: number

      The y coordinate of the point.

    • left: number

      The left coordinate of the rectangle.

    • top: number

      The top coordinate of the rectangle.

    • right: number

      The right coordinate of the rectangle.

    • bottom: number

      The bottom coordinate of the rectangle.

    Returns object

    The distance.

    • x: number
    • y: number

encodeAttrName

  • encodeAttrName(name: string, qualifier?: undefined | string): string
  • Transforms an attribute name from its unencoded form in the original XML data (before transformation for use with wed) to its encoded name.

    The first thing this algorithm does is compute a difference between the original XML name and how HTML will record it. The issue here is that XML allows more characters in a name than what HTML allows and doing setAttribute(name, value) will silently convert name to something HTML likes. The issue most frequently encountered is that uppercase letters are encoded as lowercase. This is especially vexing seeing as XML allows the attribute names x and X to exist as different attributes, whereas HTML does not. For HTML x and X are the same attribute. This function records any differences between the original name and the way HTML records it with a diff string that is appended to the final name after a dash. If nothing appears after the final dash, then the HTML name and the XML name are the same.

    A sequence of three dashes or more is converted by adding another dash. (So sequences of single dash, or a pair of dashes remain unchanged. But all sequences of 3 dashes or more gets an additional dash.)

    A colon (:) is converted to three dashes ---.

    After transformation above the name is prepended with data-wed- and it is appended with the diff described above.

    Examples:

    • foo:bar becomes data-wed-foo---bar-. Note how the diff is empty, because foo:bar can be represented as-is in HTML.

    • MOO:aBc---def becomes data-wed-moo---abc----def-u3g2u1. Note the diff suffix, which allows restoring the orignal case.

    When qualifier is used, the qualifier is added just after data-wed- and is prepended and appended with a dash. So foo:bar with the qualifier ns would become data-wed--ns-foo---bar-. The addition of a dash in front of the qualifier makes it impossible to confuse an encoding that has a qualifier from one that does not, as XML attribute names are not allowed to start with a dash.

    Parameters

    • name: string

      The unencoded name (i.e. the attribute name as it is in XML).

    • Optional qualifier: undefined | string

      An optional qualifier.

    Returns string

    The encoded name.

Private encodeDiff

  • encodeDiff(orig: string, modified: string): string
  • Encode the difference between an original string, and a modified string. This is a specialized function designed to handle the difference between the name we want to set for an attribute, and the name that HTML actually records.

    This function records the difference as a series of steps to recover the original string:

    • g[number] means take [number] characters from the modified string as they are.

    • m[number] means remove [number] characters from the modified string.

    • p[codes] means add the codes [codes] to the modified string.

    • u[number] means convert [number] characters from the modified string to uppercase.

    This is meant to be used by wed's internal code.

    Parameters

    • orig: string

      The original.

    • modified: string

      The modified string.

    Returns string

    The difference, encoded as a string.

escapeCSSClass

  • escapeCSSClass(cls: string): string
  • Escape character in CSS class that could cause trouble in CSS selectors. This is not a general solution. It supports enough for the needs of wed.

    Parameters

    • cls: string

      The class

    Returns string

    The escaped class.

fixPrototype

  • fixPrototype(obj: any, parent: Function): void
  • This is required to work around a problem when extending built-in classes like Error. Some of the constructors for these classes return a value from the constructor, which is then picked up by the constructors generated by TypeScript (same with ES6 code transpiled through Babel), and this messes up the inheritance chain.

    See https://github.com/Microsoft/TypeScript/issues/12123.

    Parameters

    • obj: any
    • parent: Function

    Returns void

getOriginalAttributes

  • getOriginalAttributes(node: Element): Record<string, string>
  • Gets all the attributes of the node that were "original" attributes in the XML document being edited, by opposition to those attributes that exist only for HTML rendering.

    Parameters

    • node: Element

      The node to process.

    Returns Record<string, string>

    An object whose keys are attribute names and values are attribute values.

getOriginalName

  • getOriginalName(el: Element): string
  • Get the original element name of a node created for wed's data tree.

    Parameters

    • el: Element

      The element whose name we want.

    Returns string

    The name.

isXMLAttrName

  • isXMLAttrName(name: string): boolean
  • Determines whether a data-wed- attribute corresponds to an XML attribute.

    Parameters

    • name: string

    Returns boolean

newGenericID

  • newGenericID(): string
  • Generates a new generic element id. This id is guaranteed to be unique for the current run of wed. The ids generated by this function are meant to be eventually replaced by something more permanent.

    Returns string

    An element id.

readFile

  • readFile(file: File): Promise<string>

seleniumLog

  • seleniumLog(...args: any[]): void
  • This function is meant to be used in debugging. It creates a selenium_log object on window which is an array that contains the series of obj passed to this function. Remember that ultimately selenium_log is going to be serialized by Selenium. So go easy on what you put in there and be aware that Selenium may have bugs that prevent serialization of certain objects.

    Parameters

    • Rest ...args: any[]

      Objects to log.

    Returns void

stackTrace

  • stackTrace(): string
  • This function is meant to be used in debugging. Gets a stack trace. This is only as cross-platform as needed for the platforms we support.

    Support for IE 9 is missing because it was designed by baboons.

    Returns string

Private stringToCodeSequence

  • stringToCodeSequence(str: string): string
  • Convert a string to a sequence of char codes. Each char code will be preceded by the character x. The char codes are converted to hexadecimal.

    This is meant to be used by wed's internal code.

    Parameters

    • str: string

      The string to encode.

    Returns string

    The encoded string.

suppressUnhandledRejections

  • suppressUnhandledRejections<P>(p: P): P
  • Type parameters

    • P: Promise<any>

    Parameters

    • p: P

    Returns P

Generated using TypeDoc