Browse Source

Consistently capitalise type names

develop
Gerben 4 months ago
parent
commit
11d2ed31b4
5 changed files with 25 additions and 25 deletions
  1. +1
    -1
      src/common.ts
  2. +13
    -13
      src/index.ts
  3. +4
    -4
      src/whatwg-dom.ts
  4. +5
    -5
      src/whatwg-html.ts
  5. +2
    -2
      src/whatwg-infra.ts

+ 1
- 1
src/common.ts View File

@@ -1,4 +1,4 @@
export type locale = string;
export type Locale = string;

export function nextNode(node: Node): Node | null {
const walker = (node.ownerDocument ?? node as Document).createTreeWalker(node.getRootNode());


+ 13
- 13
src/index.ts View File

@@ -8,7 +8,7 @@


import {
locale,
Locale,
isElement,
nextNode,
} from './common.js';
@@ -29,12 +29,12 @@ import {
} from './whatwg-html.js';

import {
asciiString,
AsciiString,
htmlNamespace,
} from './whatwg-infra.js';

type nonEmptyString = string;
type integer = number;
type NonEmptyString = string;
type Integer = number;


// § 3.3.1. Processing the fragment directive
@@ -48,7 +48,7 @@ export const fragmentDirectiveDelimiter = ':~:';
// Instead of actually modifying the document’s URL fragment and fragment directive, this implementation returns the values these should have been set to. It therefore does not take the second argument. Also it expects to receive the URL as a string instead of as a URL object.
export function processAndConsumeFragmentDirective(url: string): { url: string, documentFragmentDirective: string | null } {
// “Each document has an associated fragment directive which is either null or an ASCII string holding data used by the UA to process the resource. It is initially null.”
let documentFragmentDirective: asciiString | null = null;
let documentFragmentDirective: AsciiString | null = null;

// 1. “Let raw fragment be equal to url’s fragment.”
// (as we only have access to the serialised URL, we extract the fragment again)
@@ -86,10 +86,10 @@ export function processAndConsumeFragmentDirective(url: string): { url: string,
// https://wicg.github.io/scroll-to-text-fragment/#parsedtextdirective
// “A ParsedTextDirective is a struct that consists of four strings: textStart, textEnd, prefix, and suffix. textStart is required to be non-null. The other three items may be set to null, indicating they weren’t provided. The empty string is not a valid value for any of these items.”
export interface ParsedTextDirective {
textStart: nonEmptyString;
textEnd: nonEmptyString | null;
prefix: nonEmptyString | null;
suffix: nonEmptyString | null;
textStart: NonEmptyString;
textEnd: NonEmptyString | null;
prefix: NonEmptyString | null;
suffix: NonEmptyString | null;
};

// https://wicg.github.io/scroll-to-text-fragment/#parse-a-text-directive
@@ -170,7 +170,7 @@ export function isValidFragmentDirective(input: string | null): input is ValidFr

// https://wicg.github.io/scroll-to-text-fragment/#text-fragment-directive
// “The text fragment directive is one such fragment directive that enables specifying a piece of text on the page, that matches the production:”
export type TextDirective = asciiString; // should conform to the text directive grammar
export type TextDirective = AsciiString; // should conform to the text directive grammar
export function isTextFragmentDirective(input: string): input is TextDirective {
// TODO (use PEG.js?)
return input.startsWith('text='); // TEMP
@@ -373,7 +373,7 @@ export function scrollRangeIntoView(range: Range, behavior: ScrollBehavior, bloc
// https://wicg.github.io/scroll-to-text-fragment/#process-a-fragment-directive

// “To process a fragment directive, given as input an ASCII string fragment directive input and a Document document, run these steps:”
export function processFragmentDirective(fragmentDirectiveInput: asciiString | null, document: Document): Range[] {
export function processFragmentDirective(fragmentDirectiveInput: AsciiString | null, document: Document): Range[] {
// 1. “If fragment directive input is not a valid fragment directive, then return an empty list.”
if (!isValidFragmentDirective(fragmentDirectiveInput)) {
return [];
@@ -858,7 +858,7 @@ export function findARangeFromANodeList(queryString: string, searchRange: Range,

// https://wicg.github.io/scroll-to-text-fragment/#get-boundary-point-at-index
// “To get boundary point at index, given an integer index, list of Text nodes nodes, and a boolean isEnd, follow these steps:”
export function getBoundaryPointAtIndex(index: integer, nodes: Text[], isEnd: boolean): BoundaryPoint | null {
export function getBoundaryPointAtIndex(index: Integer, nodes: Text[], isEnd: boolean): BoundaryPoint | null {
// 1. “Let counted be 0.”
let counted = 0;

@@ -898,7 +898,7 @@ export function getBoundaryPointAtIndex(index: integer, nodes: Text[], isEnd: bo

// https://wicg.github.io/scroll-to-text-fragment/#is-at-a-word-boundary
// “A number position is at a word boundary in a string text, given a locale locale, if, using locale, …”
export function isAtWordBoundary(position: number, text: string, locale: locale) {
export function isAtWordBoundary(position: number, text: string, locale: Locale) {
// “…either a word boundary immediately precedes the positionth code unit, …”
// TODO Implement the “default word boundary specification” of the referenced unicode spec.
// TEMP Just use a regular expression to test against a pair of alphanumeric characters.


+ 4
- 4
src/whatwg-dom.ts View File

@@ -10,8 +10,8 @@ import {
nextNode,
} from './common.js';

type nonNegativeInteger = number;
type count = number;
type NonNegativeInteger = number;
type Count = number;


// https://dom.spec.whatwg.org/#concept-tree-descendant
@@ -109,7 +109,7 @@ export function isShadowIncludingInclusiveAncestor(nodeA: Node, nodeB: Node): bo
export function substringData(
node: CharacterData, // XXX The spec says “node node”, but reads “node’s data” which is only defined for CharacterData nodes.
offset: number,
count: count
count: Count
): string {
// 1. “Let length be node’s length.”
const length = nodeLength(node);
@@ -126,4 +126,4 @@ export function substringData(

// https://dom.spec.whatwg.org/#concept-range-bp
// “A boundary point is a tuple consisting of a node (a node) and an offset (a non-negative integer).”
export type BoundaryPoint = [Node, nonNegativeInteger];
export type BoundaryPoint = [Node, NonNegativeInteger];

+ 5
- 5
src/whatwg-html.ts View File

@@ -6,20 +6,20 @@


import {
locale,
Locale,
isElement,
} from './common.js';

import {
asciiWhitespace,
htmlNamespace,
AsciiWhitespace,
xmlNamespace,
} from './whatwg-infra.js';


// § 3.2.6.2 The lang and xml:lang attributes
// https://html.spec.whatwg.org/multipage/dom.html#language
export function languageOf(node: Node): locale {
export function languageOf(node: Node): Locale {
// “To determine the language of a node, user agents must look at the nearest ancestor element (including the element itself if the node is an element) that has a lang attribute in the XML namespace set or is an HTML element and has a lang in no namespace attribute set. That attribute specifies the language of the node (regardless of its value).”
let curNode: Node | null = node;
while (curNode !== null) {
@@ -73,13 +73,13 @@ export function getPragmaSetDefaultLanguage(): string | undefined {
let position = 0;

// 5. “Skip ASCII whitespace within input given position.”
while (position < input.length && AsciiWhitespace.includes(input[position]))
while (position < input.length && asciiWhitespace.includes(input[position]))
position++;

// 6. “Collect a sequence of code points that are not ASCII whitespace from input given position.”
// 7. “Let candidate be the string that resulted from the previous step.”
let candidate = '';
while (!AsciiWhitespace.includes(input[position])) {
while (!asciiWhitespace.includes(input[position])) {
candidate += input[position];
position++;
}


+ 2
- 2
src/whatwg-infra.ts View File

@@ -6,11 +6,11 @@

// https://infra.spec.whatwg.org/#ascii-whitespace
// “ASCII whitespace is U+0009 TAB, U+000A LF, U+000C FF, U+000D CR, or U+0020 SPACE.”
export const AsciiWhitespace = '\u0009\u000a\u000c\u000d\u0020';
export const asciiWhitespace = '\u0009\u000a\u000c\u000d\u0020';

// https://infra.spec.whatwg.org/#ascii-string
// “An ASCII string is a string whose code points are all ASCII code points.”
export type asciiString = string;
export type AsciiString = string;

// https://infra.spec.whatwg.org/#html-namespace
// “The HTML namespace is "http://www.w3.org/1999/xhtml".”


Loading…
Cancel
Save