@mark1russell7/site-pages 0.5.4 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -4
- package/build/demo.d.ts +4 -13
- package/build/demo.d.ts.map +1 -1
- package/build/demo.js +1 -48
- package/build/demo.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -558,9 +558,7 @@ A home page shows the package at work: a visitor types or clicks, and the page s
|
|
|
558
558
|
| `examples(row, items, pick)` | Fills a row with one button for each example `[label, value]`. A click starts `pick` with the value. |
|
|
559
559
|
| `verdict(pass, title, ...reason)` | Makes the line of a verdict: a check or a cross, a title in bold and a reason. The mark has the label "Pass" or "Fail". |
|
|
560
560
|
| `setField(field, value)` | Sets the value of a field and sends an `input` event, as typing does. |
|
|
561
|
-
| `
|
|
562
|
-
| `partsOf(text, find)` | Divides a text into parts at each copy of `find`. |
|
|
563
|
-
| `markedText(parts, label)` | Shows a text in a box, with a `mark` element on each part with `hit`. |
|
|
561
|
+
| `markedText(parts, label)` | Shows a text in a box, with a `mark` element on each part with `hit`. `partsAt` and `partsOf` of `@mark1russell7/text/parts` give the parts. |
|
|
564
562
|
|
|
565
563
|
The style gives these classes:
|
|
566
564
|
|
|
@@ -576,7 +574,8 @@ The style gives these classes:
|
|
|
576
574
|
```ts
|
|
577
575
|
import "@mark1russell7/site-pages/demo.css";
|
|
578
576
|
import { byId } from "@mark1russell7/site-pages/chrome";
|
|
579
|
-
import { examples, markedText,
|
|
577
|
+
import { examples, markedText, setField, verdict } from "@mark1russell7/site-pages/demo";
|
|
578
|
+
import { partsOf } from "@mark1russell7/text/parts";
|
|
580
579
|
|
|
581
580
|
const input = byId<HTMLInputElement>("find");
|
|
582
581
|
const result = byId("result");
|
package/build/demo.d.ts
CHANGED
|
@@ -25,23 +25,14 @@ export declare function verdict(pass: boolean, title: Child, ...reason: readonly
|
|
|
25
25
|
* Thus an example button changes a field, and the demo of the field shows the new value.
|
|
26
26
|
*/
|
|
27
27
|
export declare function setField(field: HTMLInputElement | HTMLTextAreaElement, value: string): void;
|
|
28
|
-
/**
|
|
28
|
+
/**
|
|
29
|
+
* A part of a text. `markedText` puts a `mark` element on a part with `hit`. The functions `partsAt` and `partsOf` of
|
|
30
|
+
* `@mark1russell7/text/parts` give the parts of a text.
|
|
31
|
+
*/
|
|
29
32
|
export interface TextPart {
|
|
30
33
|
readonly text: string;
|
|
31
34
|
readonly hit: boolean;
|
|
32
35
|
}
|
|
33
|
-
/**
|
|
34
|
-
* This function divides a text into parts at ranges of code units, `[start, end)`. Each range gives a
|
|
35
|
-
* part with `hit`, and the text between the ranges gives parts with no `hit`. The function sorts the
|
|
36
|
-
* ranges, joins the ranges that overlap, and clamps each range to the text. Two ranges that touch stay
|
|
37
|
-
* two parts. An empty range gives no part.
|
|
38
|
-
*/
|
|
39
|
-
export declare function partsAt(text: string, ranges: readonly (readonly [start: number, end: number])[]): TextPart[];
|
|
40
|
-
/**
|
|
41
|
-
* This function divides a text into parts at each copy of `find`, from the start, with no overlap.
|
|
42
|
-
* Each copy gives a part with `hit`. An empty `find` gives one part with no `hit`.
|
|
43
|
-
*/
|
|
44
|
-
export declare function partsOf(text: string, find: string): TextPart[];
|
|
45
36
|
/**
|
|
46
37
|
* This function shows a text in a `pre` box, with a `mark` element on each part with `hit`. The box is
|
|
47
38
|
* a group with the label, so a screen reader names it. A text with no parts shows "(empty)".
|
package/build/demo.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"demo.d.ts","names":[],"sources":["../src/demo.ts"],"mappings":";;;;;;;;;YAUY,oBAAoB,eAAe;;;;;;wBAO/B,SAAS,KAAK,aAAa,gBAAgB,WAAW,OAAO,yBAAyB;;;;;;wBAetF,QAAQ,eAAe,OAAO,UAAU,iBAAiB,UAAU;;;;;wBAanE,SAAS,OAAO,mBAAmB,qBAAqB
|
|
1
|
+
{"version":3,"file":"demo.d.ts","names":[],"sources":["../src/demo.ts"],"mappings":";;;;;;;;;YAUY,oBAAoB,eAAe;;;;;;wBAO/B,SAAS,KAAK,aAAa,gBAAgB,WAAW,OAAO,yBAAyB;;;;;;wBAetF,QAAQ,eAAe,OAAO,UAAU,iBAAiB,UAAU;;;;;wBAanE,SAAS,OAAO,mBAAmB,qBAAqB;;;;;iBASvD;WACN;WACA;;;;;;wBAOK,WAAW,gBAAgB,YAAY,gBAAgB"}
|
package/build/demo.js
CHANGED
|
@@ -46,53 +46,6 @@ function setField(field, value) {
|
|
|
46
46
|
field.dispatchEvent(new Event("input", { bubbles: true }));
|
|
47
47
|
}
|
|
48
48
|
/**
|
|
49
|
-
* This function divides a text into parts at ranges of code units, `[start, end)`. Each range gives a
|
|
50
|
-
* part with `hit`, and the text between the ranges gives parts with no `hit`. The function sorts the
|
|
51
|
-
* ranges, joins the ranges that overlap, and clamps each range to the text. Two ranges that touch stay
|
|
52
|
-
* two parts. An empty range gives no part.
|
|
53
|
-
*/
|
|
54
|
-
function partsAt(text, ranges) {
|
|
55
|
-
const clamp = (n) => Math.min(Math.max(Math.trunc(n), 0), text.length);
|
|
56
|
-
const sorted = ranges.map(([start, end]) => [clamp(start), clamp(end)]).filter(([start, end]) => end > start).sort((a, b) => a[0] - b[0]);
|
|
57
|
-
const parts = [];
|
|
58
|
-
let at = 0;
|
|
59
|
-
for (const [start, end] of sorted) {
|
|
60
|
-
if (end <= at) continue;
|
|
61
|
-
if (start < at) {
|
|
62
|
-
const last = parts[parts.length - 1];
|
|
63
|
-
parts[parts.length - 1] = {
|
|
64
|
-
text: last.text + text.slice(at, end),
|
|
65
|
-
hit: true
|
|
66
|
-
};
|
|
67
|
-
} else {
|
|
68
|
-
if (start > at) parts.push({
|
|
69
|
-
text: text.slice(at, start),
|
|
70
|
-
hit: false
|
|
71
|
-
});
|
|
72
|
-
parts.push({
|
|
73
|
-
text: text.slice(start, end),
|
|
74
|
-
hit: true
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
|
-
at = end;
|
|
78
|
-
}
|
|
79
|
-
if (at < text.length) parts.push({
|
|
80
|
-
text: text.slice(at),
|
|
81
|
-
hit: false
|
|
82
|
-
});
|
|
83
|
-
return parts;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* This function divides a text into parts at each copy of `find`, from the start, with no overlap.
|
|
87
|
-
* Each copy gives a part with `hit`. An empty `find` gives one part with no `hit`.
|
|
88
|
-
*/
|
|
89
|
-
function partsOf(text, find) {
|
|
90
|
-
if (find === "") return partsAt(text, []);
|
|
91
|
-
const ranges = [];
|
|
92
|
-
for (let at = text.indexOf(find); at >= 0; at = text.indexOf(find, at + find.length)) ranges.push([at, at + find.length]);
|
|
93
|
-
return partsAt(text, ranges);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
49
|
* This function shows a text in a `pre` box, with a `mark` element on each part with `hit`. The box is
|
|
97
50
|
* a group with the label, so a screen reader names it. A text with no parts shows "(empty)".
|
|
98
51
|
*/
|
|
@@ -104,6 +57,6 @@ function markedText(parts, label) {
|
|
|
104
57
|
"aria-label": label
|
|
105
58
|
}, nodes.length > 0 ? nodes : h("span", { class: "sp-empty" }, "(empty)"));
|
|
106
59
|
}
|
|
107
|
-
export { examples, markedText,
|
|
60
|
+
export { examples, markedText, setField, verdict };
|
|
108
61
|
|
|
109
62
|
//# sourceMappingURL=demo.js.map
|
package/build/demo.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"demo.js","names":[],"sources":["../src/demo.ts"],"sourcesContent":["/**\n * The parts of a live demo on a page. The parts are a row of example buttons, the line of a verdict,\n * a field that a script fills and a text with marks. This module imports no Node.js module, so a site\n * can bundle it. Its style is in `@mark1russell7/site-pages/demo.css`.\n *\n * @packageDocumentation\n */\nimport { h, type Child } from \"./chrome.ts\";\n\n/** An example of a demo: the label of its button and the value that a click gives. */\nexport type Example = readonly [label: string, value: string];\n\n/**\n * This function fills a row with one button for each example, and gives the buttons. A click on a\n * button starts `pick` with the value of its example. When the value is not the label, the `title` of\n * the button is the value, so a pointer shows the full value.\n */\nexport function examples(row: HTMLElement, items: readonly Example[], pick: (value: string) => void): HTMLButtonElement[] {\n const buttons = items.map(([label, value]) => {\n const button = h(\"button\", { type: \"button\", class: \"sp-example\", title: value === label ? undefined : value }, label);\n button.addEventListener(\"click\", () => pick(value));\n return button;\n });\n row.replaceChildren(...buttons);\n return buttons;\n}\n\n/**\n * This function makes the line of a verdict: a mark, a title in bold and a reason. The mark is a check\n * for a pass and a cross for a fail. Its label tells the same to a screen reader, so the color is not\n * the only cue. The title has no punctuation of its own: give \"Correct:\" for a colon.\n */\nexport function verdict(pass: boolean, title: Child, ...reason: readonly Child[]): HTMLDivElement {\n return h(\n \"div\",\n { class: pass ? \"sp-verdict sp-pass\" : \"sp-verdict sp-fail\" },\n h(\"span\", { class: \"sp-mark\", role: \"img\", \"aria-label\": pass ? \"Pass\" : \"Fail\" }, pass ? \"✓\" : \"✕\"),\n h(\"div\", {}, h(\"b\", {}, title), reason.length > 0 ? \" \" : null, ...reason),\n );\n}\n\n/**\n * This function sets the value of a field and sends an `input` event that bubbles, as typing does.\n * Thus an example button changes a field, and the demo of the field shows the new value.\n */\nexport function setField(field: HTMLInputElement | HTMLTextAreaElement, value: string): void {\n field.value = value;\n field.dispatchEvent(new Event(\"input\", { bubbles: true }));\n}\n\n
|
|
1
|
+
{"version":3,"file":"demo.js","names":[],"sources":["../src/demo.ts"],"sourcesContent":["/**\n * The parts of a live demo on a page. The parts are a row of example buttons, the line of a verdict,\n * a field that a script fills and a text with marks. This module imports no Node.js module, so a site\n * can bundle it. Its style is in `@mark1russell7/site-pages/demo.css`.\n *\n * @packageDocumentation\n */\nimport { h, type Child } from \"./chrome.ts\";\n\n/** An example of a demo: the label of its button and the value that a click gives. */\nexport type Example = readonly [label: string, value: string];\n\n/**\n * This function fills a row with one button for each example, and gives the buttons. A click on a\n * button starts `pick` with the value of its example. When the value is not the label, the `title` of\n * the button is the value, so a pointer shows the full value.\n */\nexport function examples(row: HTMLElement, items: readonly Example[], pick: (value: string) => void): HTMLButtonElement[] {\n const buttons = items.map(([label, value]) => {\n const button = h(\"button\", { type: \"button\", class: \"sp-example\", title: value === label ? undefined : value }, label);\n button.addEventListener(\"click\", () => pick(value));\n return button;\n });\n row.replaceChildren(...buttons);\n return buttons;\n}\n\n/**\n * This function makes the line of a verdict: a mark, a title in bold and a reason. The mark is a check\n * for a pass and a cross for a fail. Its label tells the same to a screen reader, so the color is not\n * the only cue. The title has no punctuation of its own: give \"Correct:\" for a colon.\n */\nexport function verdict(pass: boolean, title: Child, ...reason: readonly Child[]): HTMLDivElement {\n return h(\n \"div\",\n { class: pass ? \"sp-verdict sp-pass\" : \"sp-verdict sp-fail\" },\n h(\"span\", { class: \"sp-mark\", role: \"img\", \"aria-label\": pass ? \"Pass\" : \"Fail\" }, pass ? \"✓\" : \"✕\"),\n h(\"div\", {}, h(\"b\", {}, title), reason.length > 0 ? \" \" : null, ...reason),\n );\n}\n\n/**\n * This function sets the value of a field and sends an `input` event that bubbles, as typing does.\n * Thus an example button changes a field, and the demo of the field shows the new value.\n */\nexport function setField(field: HTMLInputElement | HTMLTextAreaElement, value: string): void {\n field.value = value;\n field.dispatchEvent(new Event(\"input\", { bubbles: true }));\n}\n\n/**\n * A part of a text. `markedText` puts a `mark` element on a part with `hit`. The functions `partsAt` and `partsOf` of\n * `@mark1russell7/text/parts` give the parts of a text.\n */\nexport interface TextPart {\n readonly text: string;\n readonly hit: boolean;\n}\n\n/**\n * This function shows a text in a `pre` box, with a `mark` element on each part with `hit`. The box is\n * a group with the label, so a screen reader names it. A text with no parts shows \"(empty)\".\n */\nexport function markedText(parts: readonly TextPart[], label: string): HTMLPreElement {\n const nodes = parts.filter((part) => part.text !== \"\").map((part) => (part.hit ? h(\"mark\", {}, part.text) : part.text));\n return h(\"pre\", { class: \"sp-text\", role: \"group\", \"aria-label\": label }, nodes.length > 0 ? nodes : h(\"span\", { class: \"sp-empty\" }, \"(empty)\"));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astore.org/package",
|
|
3
3
|
"name": "@mark1russell7/site-pages",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"description": "A release timeline page and a live status page for the site of a GitHub repository: JSON data and standalone HTML, made at deploy time.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"github-pages",
|