@astl/core 0.0.0-stage → 0.1.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.
Files changed (139) hide show
  1. package/CHANGELOG.md +54 -0
  2. package/LICENSE +202 -0
  3. package/README.md +37 -2
  4. package/dist/answers.d.ts +29 -0
  5. package/dist/answers.d.ts.map +1 -0
  6. package/dist/answers.js +40 -0
  7. package/dist/answers.js.map +1 -0
  8. package/dist/ast.d.ts +25 -0
  9. package/dist/ast.d.ts.map +1 -0
  10. package/dist/ast.js +27 -0
  11. package/dist/ast.js.map +1 -0
  12. package/dist/authoring.d.ts +451 -0
  13. package/dist/authoring.d.ts.map +1 -0
  14. package/dist/authoring.js +2 -0
  15. package/dist/authoring.js.map +1 -0
  16. package/dist/checker.d.ts +78 -0
  17. package/dist/checker.d.ts.map +1 -0
  18. package/dist/checker.js +10 -0
  19. package/dist/checker.js.map +1 -0
  20. package/dist/compiled.d.ts +94 -0
  21. package/dist/compiled.d.ts.map +1 -0
  22. package/dist/compiled.js +16 -0
  23. package/dist/compiled.js.map +1 -0
  24. package/dist/content.d.ts +72 -0
  25. package/dist/content.d.ts.map +1 -0
  26. package/dist/content.js +128 -0
  27. package/dist/content.js.map +1 -0
  28. package/dist/declarations.d.ts +52 -0
  29. package/dist/declarations.d.ts.map +1 -0
  30. package/dist/declarations.js +358 -0
  31. package/dist/declarations.js.map +1 -0
  32. package/dist/definition.d.ts +106 -0
  33. package/dist/definition.d.ts.map +1 -0
  34. package/dist/definition.js +2 -0
  35. package/dist/definition.js.map +1 -0
  36. package/dist/engine.d.ts +95 -0
  37. package/dist/engine.d.ts.map +1 -0
  38. package/dist/engine.js +2 -0
  39. package/dist/engine.js.map +1 -0
  40. package/dist/format.d.ts +29 -0
  41. package/dist/format.d.ts.map +1 -0
  42. package/dist/format.js +55 -0
  43. package/dist/format.js.map +1 -0
  44. package/dist/help.d.ts +38 -0
  45. package/dist/help.d.ts.map +1 -0
  46. package/dist/help.js +22 -0
  47. package/dist/help.js.map +1 -0
  48. package/dist/i18n/check.d.ts +11 -0
  49. package/dist/i18n/check.d.ts.map +1 -0
  50. package/dist/i18n/check.js +64 -0
  51. package/dist/i18n/check.js.map +1 -0
  52. package/dist/i18n/format.d.ts +40 -0
  53. package/dist/i18n/format.d.ts.map +1 -0
  54. package/dist/i18n/format.js +280 -0
  55. package/dist/i18n/format.js.map +1 -0
  56. package/dist/i18n/i18n.d.ts +14 -0
  57. package/dist/i18n/i18n.d.ts.map +1 -0
  58. package/dist/i18n/i18n.js +82 -0
  59. package/dist/i18n/i18n.js.map +1 -0
  60. package/dist/i18n/types.d.ts +31 -0
  61. package/dist/i18n/types.d.ts.map +1 -0
  62. package/dist/i18n/types.js +7 -0
  63. package/dist/i18n/types.js.map +1 -0
  64. package/dist/index.d.ts +45 -0
  65. package/dist/index.d.ts.map +1 -0
  66. package/dist/index.js +21 -0
  67. package/dist/index.js.map +1 -0
  68. package/dist/issues.d.ts +98 -0
  69. package/dist/issues.d.ts.map +1 -0
  70. package/dist/issues.js +74 -0
  71. package/dist/issues.js.map +1 -0
  72. package/dist/json.d.ts +7 -0
  73. package/dist/json.d.ts.map +1 -0
  74. package/dist/json.js +2 -0
  75. package/dist/json.js.map +1 -0
  76. package/dist/manifest.d.ts +135 -0
  77. package/dist/manifest.d.ts.map +1 -0
  78. package/dist/manifest.js +63 -0
  79. package/dist/manifest.js.map +1 -0
  80. package/dist/player.d.ts +129 -0
  81. package/dist/player.d.ts.map +1 -0
  82. package/dist/player.js +18 -0
  83. package/dist/player.js.map +1 -0
  84. package/dist/policy.d.ts +53 -0
  85. package/dist/policy.d.ts.map +1 -0
  86. package/dist/policy.js +55 -0
  87. package/dist/policy.js.map +1 -0
  88. package/dist/protocol.d.ts +54 -0
  89. package/dist/protocol.d.ts.map +1 -0
  90. package/dist/protocol.js +51 -0
  91. package/dist/protocol.js.map +1 -0
  92. package/dist/result.d.ts +44 -0
  93. package/dist/result.d.ts.map +1 -0
  94. package/dist/result.js +5 -0
  95. package/dist/result.js.map +1 -0
  96. package/dist/scoring.d.ts +27 -0
  97. package/dist/scoring.d.ts.map +1 -0
  98. package/dist/scoring.js +6 -0
  99. package/dist/scoring.js.map +1 -0
  100. package/dist/slots.d.ts +47 -0
  101. package/dist/slots.d.ts.map +1 -0
  102. package/dist/slots.js +9 -0
  103. package/dist/slots.js.map +1 -0
  104. package/dist/snapshot.d.ts +23 -0
  105. package/dist/snapshot.d.ts.map +1 -0
  106. package/dist/snapshot.js +22 -0
  107. package/dist/snapshot.js.map +1 -0
  108. package/dist/style.d.ts +51 -0
  109. package/dist/style.d.ts.map +1 -0
  110. package/dist/style.js +36 -0
  111. package/dist/style.js.map +1 -0
  112. package/package.json +40 -3
  113. package/src/answers.ts +52 -0
  114. package/src/ast.ts +49 -0
  115. package/src/authoring.ts +475 -0
  116. package/src/checker.ts +91 -0
  117. package/src/compiled.ts +115 -0
  118. package/src/content.ts +156 -0
  119. package/src/declarations.ts +427 -0
  120. package/src/definition.ts +104 -0
  121. package/src/engine.ts +98 -0
  122. package/src/format.ts +67 -0
  123. package/src/help.ts +41 -0
  124. package/src/i18n/check.ts +67 -0
  125. package/src/i18n/format.ts +318 -0
  126. package/src/i18n/i18n.ts +92 -0
  127. package/src/i18n/types.ts +35 -0
  128. package/src/index.ts +201 -0
  129. package/src/issues.ts +107 -0
  130. package/src/json.ts +6 -0
  131. package/src/manifest.ts +193 -0
  132. package/src/player.ts +145 -0
  133. package/src/policy.ts +117 -0
  134. package/src/protocol.ts +65 -0
  135. package/src/result.ts +53 -0
  136. package/src/scoring.ts +31 -0
  137. package/src/slots.ts +57 -0
  138. package/src/snapshot.ts +40 -0
  139. package/src/style.ts +89 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,54 @@
1
+ # @astl/core
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 402924c: A document can be a book: `<astl-doc lang="en" kind="book">`. `kind` is how it shows, never how it grades: `exercise` (the default, as before) one page at a time; `book` two pages side by side (1-2, 3-4, ...) once the player is at least 56rem wide, where "Next" and "Back" turn a spread with a short slide (none under reduced motion or forced colours) and the counter says "Pages 1-2 of 5"; narrower, one page at a time. Another value is `ATTRIBUTE_INVALID`. The compiled view and `Metadata.kind` carry the kind only when it is not `exercise`, so views and metadata of existing content stay byte for byte as they were. `DOC_KINDS`, `DocKind` and `DEFAULT_DOC_KIND` are exported from `@astl/core`. Example: `examples/book`.
8
+ - 97e412c: Authors' own styles, column layouts and named styles in the content format.
9
+
10
+ - `style` on every element, checked by an allow-list (`cleanStyle`, `@astl/core/declarations`): what it refuses goes with
11
+ a warning, `STYLE_REMOVED`. `STYLE_LOW_CONTRAST` warns about text that is hard to read.
12
+ - `<astl-columns>` with 2 to 4 `<astl-column>` on a page, wrapping by themselves on a phone.
13
+ - `<astl-style>` first in `<astl-doc>`, by `name` (applied by `class`) or `for` a tag. The engine writes them into each
14
+ element: a view holds only `style`.
15
+ - The player draws them from a chunk that only such a view loads, through the CSSOM (a strict CSP allows it), following
16
+ the theme, and stays within the column on any screen.
17
+ - The TipTap surface keeps them on every node and mark, shows them, and keeps block moves, page breaks and
18
+ `EditorAdapter.insert` inside a column. A paste keeps what the allow-list allows, and only classes the document defines.
19
+ - ec2a249: The editor works like a word processor with block cards.
20
+
21
+ - `<astl-toolbar>`, part of `<astl-editor>`: the text style menu, bold, italic, underline, link, the two lists, undo and redo, the host's featured inserts as buttons (`featured`, from `defineEditor` or the element; `@astl/astrolabe` features text, gap, closed question, ordering, sort into groups and picture) and "More", the insert menu in a searchable popover. One tab stop with the arrow keys; a press never moves the cursor. Its groups wrap into rows, the inserts on a row of their own; only under 30rem (a phone) is it one row that scrolls sideways.
22
+ - Block cards in the TipTap surface: each block's head gives its number, type and points, with buttons to move it up or down and delete it (one undo step each, said on the status line), and "Add block" ends each page. Chips show their answer with an icon and "+N"; an option's correct marker is a toggle before its text, and "Add option" follows the last one. A card whose block has errors or warnings is dashed, in the colour of its worst issue, and says them under its head without the page ("Gap 1 has no answer."). Each page's head says "Page 2 of 3", and its title field has the visible label "Page title".
23
+ - Hosts theme the surface with `--astl-editor-*` custom properties: the sheet (corners, padding, border, focus ring), the cards (corners, padding), the card with the cursor (a ring, its kicker's colour), the kickers' size, the chips, the correct marker and the option rows (reference/editor.md, "Theming the surface").
24
+ - `label.text` ("{label}: {text}") names the insert menu's entries, the issues, the chips and the markers, so a screen reader says "Gap: The student types a word or a number." with no space before the colon.
25
+ - `EditorAdapter` has optional capabilities: `format` and `formatState`, `undo` and `redo`, `moveBlock` and `removeBlock`, `getCursor` and `onCursorChange`, `selectedText`, `focus`, and `insert(html, { replaceSelection })`. Adapters without them keep working; their controls are left out.
26
+ - `authoring.outline(source)` lists each page's blocks with their points and issue counts; `authoring.describe(issue, source)` names a component as the author sees it, never by its id (a block component by its block's number on its page, "Question 2 on page 1", a component in text by its number among its type), and with `{ page: false }` (`DescribeOptions`) without its page ("Question 2"), for a host that shows the page apart; a template's `{{selection}}` takes the selected text (a gap made from a word).
27
+ - `<astl-editor>`: `ready` and `astl-editor-ready`, `preview()`, `panels` (an empty list leaves the side column to the host's own `<astl-inspector>`).
28
+ - `@astl/astrolabe/editor` exports `createAuthoring` and its types; importing it in Node touches no DOM.
29
+ - The TipTap surface's stylesheet comes with the surface: `<astl-editor>`'s first load no longer carries it.
30
+
31
+ Breaking: `<astl-editor>` has no `insert-menu` or `tools` part (the menu is the toolbar's `more-menu`, the types' commands are toolbar buttons), and the inspector's heading names the type only, with the id in its `data-id`. The messages `surface.flag` and `surface.chip.title` give way to `label.text`, `surface.pageTitleName` is gone (the title field is named by its label and the page number), and `surface.pageNumber` takes `{pages}`.
32
+ - cfa6485: The editor reads like a word processor: one flowing text per page, with its elements framed.
33
+
34
+ - The TipTap surface frames each block component, with a label tab at the frame's top start: the type's icon, its name in bold and a summary of its items and points ("Closed question · 4 items · 1 pt", "4 elementy · 1 pkt"), never an id. Text runs are unframed. The frame with the cursor is in the accent, its tab filled; a frame with issues is dashed in the colour of the worst one and says them under its tab, without the page.
35
+ - The inspector's head gives the type and "Move up", "Move down" and "Delete" for the block component with the cursor (the adapter's `moveBlock` and `removeBlock`, left out without them): one undo step each, said in the editor's live region.
36
+ - The toolbar, in order: text style, bold, italic, underline, link, lists; the featured inserts, "Elements" (every component, "Picture", "Page break") and "Templates" (the starters), two searchable popovers whose entries have an icon, a name and a line on what they do; "Mark word"; the view switch; undo and redo. `openMenu('elements' | 'templates')` opens a menu; `<astl-insert-menu>` takes `groups`.
37
+ - The insert menus' lines are a catalog of their own per type (`messages/menu/<locale>.json`, `<type>MenuMessages`, all of them in `builtInMenuMessages` of `@astl/components/menu-messages`), which the editors load when a menu first opens: the `menuMessages` option of `defineEditor` and `createAuthoring`, and `authoring.loadMenuMessages()`. Every built-in component and starter has a one-line description in English and Polish.
38
+ - Pages can be deleted: `removePage(id)`, optional in `EditorAdapter` and in the TipTap adapter, deletes a page and everything on it, the cursor at the start of the page before (of the next one for the first page), one undo step; `false` for the only page or an unknown id. Each page head of the TipTap surface has a "Delete page" button while there are other pages, and the status message says "Deleted page 2".
39
+ - A status line under the toolbar (`part="status-line"`) counts the elements and points and says "Ready to share", or how many errors and warnings there are. It is not a live region.
40
+ - Views: `<astl-editor>` has `view` (`visual`, `source` or a host view) and `views` (the host's `{ name, label }`, an option, an attribute in JSON or a property); `source` shows the document's HTML in a monospace text area (`part="source"`), applied on the way back and kept, with its errors listed, while it has errors; a host view shows the `view-{name}` slot. Each change dispatches `astl-editor-view` (`detail: { view }`, bubbles, composed).
41
+
42
+ Breaking:
43
+
44
+ - The block cards are gone: no card heads, points fields, move and delete buttons on the surface, no "Add block" and no `astl-add-block` event.
45
+ - The surface hooks `--astl-editor-card-radius`, `--astl-editor-card-padding` and `--astl-editor-card-current-ring` are `--astl-editor-frame-radius`, `--astl-editor-frame-padding` and `--astl-editor-frame-current-ring`; `--astl-editor-card-current-kicker` is gone.
46
+ - `<astl-toolbar>`: "More" is "Elements" and "Templates"; `openMore()` is `openMenu(menu)`; the parts `more` and `more-menu` are `insert` and `insert-menu`, the icon part `icon-more` is `icon-add`.
47
+ - `DEFAULT_FEATURED` is empty: `@astl/astrolabe` features no inserts; pass `featured` to get buttons back.
48
+ - The kit's messages `toolbar.more`, `surface.blockTitle`, `surface.pointsField`, `surface.pointsUnit`, `surface.moveUp`, `surface.moveDown`, `surface.remove` and `surface.addBlock` are gone; `editor.description` and the starters' `template.*.description` moved from each type's `messages/<locale>.json` to `messages/menu/<locale>.json`.
49
+ - 4611aeb: The editor gets styles. `EditorAdapter.style` is a new optional capability, implemented on the TipTap surface. The toolbar has font, size, text colour, highlight, alignment, spacing, a style menu and clear formatting; `defineEditor({ fonts })` sets its fonts. `<astl-style-form>` (with "Own CSS", which shows what the allow-list refused, and "Save as a style") and `<astl-style-rules>` load on first use, and `astl-style-open` lets a host show them in its own place. Pictures and figures show their position and width, with a corner handle and a field that write the same. The insert menu has a group "Layout". A component in a narrow column of the surface keeps its words whole (`--astl-editor-column-with-component`).
50
+ - 6a4f220: The first release on npm, under the scope `@astl`: `@astl/astrolabe` with everything on by default, and the single packages it is built from, all at one version.
51
+ - c500ae1: Layouts get a toolbar button of their own, "Layout", and "Elements" no longer lists them. A layout can now be removed or changed once inserted: a tab over every layout (its commands in the same row while the cursor is in it) and the layout's style form have "Change layout" (the content stays), "Remove layout" (the columns go, their content stays in place) and "Delete with content" (asked first when it holds anything), and Backspace removes an empty one; `EditorStyles.layout()` and `EditorStyles.editLayout(edit)` (optional) do the same for any adapter. Exercises are placed and sized like pictures: position and width in their card, a handle on the frame edge away from the float and the position line in the tab row, text beside them in the player from 30rem and stacked below. `Placement` and `PLACEMENTS` name the positions (`PicturePosition` and `PICTURE_POSITIONS` stay, deprecated); `LAYOUT_SHAPES`, `LAYOUT_COLUMNS` and `splitPlacement` are new.
52
+ - 871b57a: `<astl-mark-words>` takes an optional `<astl-prompt>` before its passage, with inline formatting, shown above the hint as the prompt of every other block type. Passages without one are valid and look as before (the hint now sits in a legend, as everywhere). For type authors: a child of a rich block (`content: 'flow'`) declared with `place: 'lead'` comes first, before the content, and nowhere else (`PLACEMENT_INVALID`); the TipTap surface edits it as a node before the content. The notebook look sets it in the book face, as the other prompts.
53
+ - 3a4945c: Ready styles, like a word processor's built-in ones. The style menu has a group "Ready styles" after "My styles", and the style form's named field a group of the same name: Note, Tip, Important, Definition, Example and Quote go on what the cursor is in, Highlight and Small print on the selected words. Picking one adds its `<astl-style>` rule to the document, labelled in the editor's language, and sets the class in one undo step; from then on it is one of "My styles", and a document with its own rule of that name keeps it. `defineEditor({ styles })` and `createAuthoring({ styles })` replace them (`[]`: none; type `EditorStylePreset`, default `DEFAULT_STYLES`, `Authoring.styles`), and a style the allow-list refuses throws. `EditorStyles.setClass(where, name, rule)` takes the rule of a ready style. The style menu scrolls when it is taller than the window.
54
+ - 64af38f: Help for students. Three elements of the content format, inside a graded component or on a page: `<astl-hint cost>` (hints on request, one at a time, each costing a share of the points), `<astl-explanation>` (under "Why?" after a check) and `<astl-feedback when="correct|incorrect|partial|omitted">` (a text by the verdict). Compiling moves them into the key (`AnswerKey.help`); the view keeps only what is offered (`hints`, `explanation`, `feedback`). `AttemptPolicy` gets optional `hints`, `checkScope`, `feedback` and `explanations`, whose defaults by mode (`helpPolicy`, `PRACTICE_POLICY`, `TEST_POLICY`) keep old hosts working. The protocol gets `check({ answers, element })` for one interaction, `feedback` and `explanations` on responses, and `POST /hint` (`Checker.hint`, `hints_not_allowed`, `hints_exhausted`); grading takes `hintsUsed`. The server binding serves all of it and records hints with `AttemptStore.recordHint`. The player loads its help module only for views with help: "Hint (1/2)" with the cost said first, "Check" of one interaction, a feedback box by the verdict, "Why?", a page's help at its foot. The editor's card has "Help for students" (hints with cost and order, the explanation, the four feedback texts), "Elements" has "Hint", "Explanation" and "Feedback", the surface shows labelled boxes, and the preview plays them in practice. New issues: `HINT_COST_INVALID`, `FEEDBACK_WHEN_INVALID`, `FEEDBACK_DUPLICATE`, `EXPLANATION_DUPLICATE`, `HELP_UNGRADED`, `HELP_EMPTY`.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,38 @@
1
- # Temporary Holding Version
1
+ # @astl/core
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Contracts and types of Astrolabe: content model, manifests, slots, scoring, checker protocol, i18n runtime. No
4
+ runtime dependencies.
5
+
6
+ ## Install
7
+
8
+ ```sh
9
+ npm install @astl/core
10
+ ```
11
+
12
+ ## Use
13
+
14
+ The player's events, the attempt policies and the types every other package shares live here:
15
+
16
+ ```ts
17
+ import { PlayerEvent, type Snapshot } from '@astl/core';
18
+
19
+ const player = document.querySelector('astl-player')!;
20
+ player.addEventListener(PlayerEvent.snapshot, (event) => {
21
+ const snapshot = (event as CustomEvent<Snapshot>).detail;
22
+ void fetch('/api/drafts/123', { method: 'PUT', body: JSON.stringify(snapshot) });
23
+ });
24
+ ```
25
+
26
+ `PRACTICE_POLICY` and `TEST_POLICY` are the policies a grading server starts attempts with, and
27
+ `@astl/core/declarations` checks the `style` values authors write.
28
+
29
+ ## This package or @astl/astrolabe
30
+
31
+ Every Astrolabe package builds on these contracts, and `@astl/astrolabe` brings them along. Install `@astl/core` on
32
+ its own when you need only the types and constants: in a backend that stores attempts, or in a component of your own.
33
+
34
+ Documentation: <https://astrolabe.starship.education/reference/contracts/>
35
+
36
+ ## License
37
+
38
+ Apache-2.0, see [LICENSE](https://github.com/starship1337/astrolabe/blob/main/LICENSE).
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Answers on the wire. Strings only, so any backend in any language can store and grade them.
3
+ * - A missing key or `''` means unanswered.
4
+ * - Text and number slots: what the student typed.
5
+ * - Choice slots: the picked value, an opaque option id or a fixed public value (`true` / `false` of a statement).
6
+ * - Flag slots (selection): `'true'` when selected.
7
+ * - Open slots: what the student wrote, kept for a teacher.
8
+ */
9
+ export type SlotId = string;
10
+ export type Answers = Readonly<Record<SlotId, string>>;
11
+ /**
12
+ * Longest accepted answer per slot, in Unicode code points, for every slot kind but `open`. Longer values count as
13
+ * unanswered (engine, servers, protocol 1).
14
+ */
15
+ export declare const MAX_ANSWER_LENGTH = 500;
16
+ /** The built-in slot kind of open answers: stored with the attempt for a teacher, never graded. */
17
+ export declare const OPEN_SLOT_KIND = "open";
18
+ /** Longest open answer, in Unicode code points (so Polish and English letters count one each). */
19
+ export declare const MAX_OPEN_ANSWER_LENGTH = 2000;
20
+ /** Most slots one request may carry. */
21
+ export declare const MAX_ANSWER_COUNT = 2000;
22
+ export declare const FLAG_SELECTED = "true";
23
+ /** The longest answer a slot of `kind` accepts, in code points: 2000 for open slots, 500 for the others. */
24
+ export declare function maxAnswerLength(kind: string | undefined): number;
25
+ /** Whether `value` is within the length limit of a slot of `kind`, counted in Unicode code points. */
26
+ export declare function fitsAnswer(value: string, kind?: string): boolean;
27
+ /** Type guard for untrusted input (request bodies, storage). */
28
+ export declare function isAnswers(value: unknown): value is Answers;
29
+ //# sourceMappingURL=answers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"answers.d.ts","sourceRoot":"","sources":["../src/answers.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC;AAE5B,MAAM,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAEvD;;;GAGG;AACH,eAAO,MAAM,iBAAiB,MAAM,CAAC;AAErC,mGAAmG;AACnG,eAAO,MAAM,cAAc,SAAS,CAAC;AAErC,kGAAkG;AAClG,eAAO,MAAM,sBAAsB,OAAO,CAAC;AAE3C,wCAAwC;AACxC,eAAO,MAAM,gBAAgB,OAAO,CAAC;AAErC,eAAO,MAAM,aAAa,SAAS,CAAC;AAEpC,4GAA4G;AAC5G,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,CAEhE;AAED,sGAAsG;AACtG,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,OAAO,CAQhE;AAED,gEAAgE;AAChE,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,OAAO,CAK1D"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Longest accepted answer per slot, in Unicode code points, for every slot kind but `open`. Longer values count as
3
+ * unanswered (engine, servers, protocol 1).
4
+ */
5
+ export const MAX_ANSWER_LENGTH = 500;
6
+ /** The built-in slot kind of open answers: stored with the attempt for a teacher, never graded. */
7
+ export const OPEN_SLOT_KIND = 'open';
8
+ /** Longest open answer, in Unicode code points (so Polish and English letters count one each). */
9
+ export const MAX_OPEN_ANSWER_LENGTH = 2000;
10
+ /** Most slots one request may carry. */
11
+ export const MAX_ANSWER_COUNT = 2000;
12
+ export const FLAG_SELECTED = 'true';
13
+ /** The longest answer a slot of `kind` accepts, in code points: 2000 for open slots, 500 for the others. */
14
+ export function maxAnswerLength(kind) {
15
+ return kind === OPEN_SLOT_KIND ? MAX_OPEN_ANSWER_LENGTH : MAX_ANSWER_LENGTH;
16
+ }
17
+ /** Whether `value` is within the length limit of a slot of `kind`, counted in Unicode code points. */
18
+ export function fitsAnswer(value, kind) {
19
+ const max = maxAnswerLength(kind);
20
+ // Code points never outnumber UTF-16 units, and each takes at most two: count only in between.
21
+ if (value.length <= max)
22
+ return true;
23
+ if (value.length > 2 * max)
24
+ return false;
25
+ let count = 0;
26
+ for (const _ of value)
27
+ if (++count > max)
28
+ return false;
29
+ return true;
30
+ }
31
+ /** Type guard for untrusted input (request bodies, storage). */
32
+ export function isAnswers(value) {
33
+ if (typeof value !== 'object' || value === null || Array.isArray(value))
34
+ return false;
35
+ const entries = Object.entries(value);
36
+ if (entries.length > MAX_ANSWER_COUNT)
37
+ return false;
38
+ return entries.every(([k, v]) => k.length > 0 && k.length <= 200 && typeof v === 'string');
39
+ }
40
+ //# sourceMappingURL=answers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"answers.js","sourceRoot":"","sources":["../src/answers.ts"],"names":[],"mappings":"AAYA;;;GAGG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,GAAG,CAAC;AAErC,mGAAmG;AACnG,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC;AAErC,kGAAkG;AAClG,MAAM,CAAC,MAAM,sBAAsB,GAAG,IAAI,CAAC;AAE3C,wCAAwC;AACxC,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,CAAC;AAErC,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC;AAEpC,4GAA4G;AAC5G,MAAM,UAAU,eAAe,CAAC,IAAwB;IACtD,OAAO,IAAI,KAAK,cAAc,CAAC,CAAC,CAAC,sBAAsB,CAAC,CAAC,CAAC,iBAAiB,CAAC;AAC9E,CAAC;AAED,sGAAsG;AACtG,MAAM,UAAU,UAAU,CAAC,KAAa,EAAE,IAAa;IACrD,MAAM,GAAG,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IAClC,+FAA+F;IAC/F,IAAI,KAAK,CAAC,MAAM,IAAI,GAAG;QAAE,OAAO,IAAI,CAAC;IACrC,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,GAAG,GAAG;QAAE,OAAO,KAAK,CAAC;IACzC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,CAAC,IAAI,KAAK;QAAE,IAAI,EAAE,KAAK,GAAG,GAAG;YAAE,OAAO,KAAK,CAAC;IACvD,OAAO,IAAI,CAAC;AACd,CAAC;AAED,gEAAgE;AAChE,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACtF,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IACtC,IAAI,OAAO,CAAC,MAAM,GAAG,gBAAgB;QAAE,OAAO,KAAK,CAAC;IACpD,OAAO,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,GAAG,IAAI,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC;AAC7F,CAAC"}
package/dist/ast.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ /**
2
+ * The document tree the engine and component definitions work on. Produced by the engine's HTML parser
3
+ * (sources) and serialised back to HTML (views). Plain data: no DOM, no parent pointers.
4
+ */
5
+ export interface ElementNode {
6
+ readonly type: 'element';
7
+ /** Lowercase tag name, e.g. `p`, `astl-gap`. */
8
+ readonly tag: string;
9
+ /** Attributes in source order. Values are already entity-decoded. */
10
+ readonly attrs: Readonly<Record<string, string>>;
11
+ readonly children: readonly Node[];
12
+ }
13
+ export interface TextNode {
14
+ readonly type: 'text';
15
+ readonly value: string;
16
+ }
17
+ export type Node = ElementNode | TextNode;
18
+ export declare function element(tag: string, attrs?: Readonly<Record<string, string>>, children?: readonly Node[]): ElementNode;
19
+ export declare function text(value: string): TextNode;
20
+ export declare function isElement(node: Node | undefined, tag?: string): node is ElementNode;
21
+ /** Concatenated text of a subtree, like DOM `textContent`. */
22
+ export declare function textContent(node: Node): string;
23
+ /** Element children with the given tag, in order. */
24
+ export declare function childElements(node: ElementNode, tag?: string): ElementNode[];
25
+ //# sourceMappingURL=ast.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,gDAAgD;IAChD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,qEAAqE;IACrE,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACjD,QAAQ,CAAC,QAAQ,EAAE,SAAS,IAAI,EAAE,CAAC;CACpC;AAED,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,MAAM,IAAI,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE1C,wBAAgB,OAAO,CACrB,GAAG,EAAE,MAAM,EACX,KAAK,GAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM,EAC5C,QAAQ,GAAE,SAAS,IAAI,EAAO,GAC7B,WAAW,CAEb;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,CAE5C;AAED,wBAAgB,SAAS,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,IAAI,IAAI,WAAW,CAEnF;AAED,8DAA8D;AAC9D,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,CAK9C;AAED,qDAAqD;AACrD,wBAAgB,aAAa,CAAC,IAAI,EAAE,WAAW,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,WAAW,EAAE,CAE5E"}
package/dist/ast.js ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * The document tree the engine and component definitions work on. Produced by the engine's HTML parser
3
+ * (sources) and serialised back to HTML (views). Plain data: no DOM, no parent pointers.
4
+ */
5
+ export function element(tag, attrs = {}, children = []) {
6
+ return { type: 'element', tag, attrs, children };
7
+ }
8
+ export function text(value) {
9
+ return { type: 'text', value };
10
+ }
11
+ export function isElement(node, tag) {
12
+ return node !== undefined && node.type === 'element' && (tag === undefined || node.tag === tag);
13
+ }
14
+ /** Concatenated text of a subtree, like DOM `textContent`. */
15
+ export function textContent(node) {
16
+ if (node.type === 'text')
17
+ return node.value;
18
+ let out = '';
19
+ for (const child of node.children)
20
+ out += textContent(child);
21
+ return out;
22
+ }
23
+ /** Element children with the given tag, in order. */
24
+ export function childElements(node, tag) {
25
+ return node.children.filter((c) => isElement(c, tag));
26
+ }
27
+ //# sourceMappingURL=ast.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ast.js","sourceRoot":"","sources":["../src/ast.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAkBH,MAAM,UAAU,OAAO,CACrB,GAAW,EACX,KAAK,GAAqC,EAAE,EAC5C,QAAQ,GAAoB,EAAE;IAE9B,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC;AACnD,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,KAAa;IAChC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,IAAsB,EAAE,GAAY;IAC5D,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,CAAC,GAAG,KAAK,SAAS,IAAI,IAAI,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;AAClG,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,WAAW,CAAC,IAAU;IACpC,IAAI,IAAI,CAAC,IAAI,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC;IAC5C,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,MAAM,KAAK,IAAI,IAAI,CAAC,QAAQ;QAAE,GAAG,IAAI,WAAW,CAAC,KAAK,CAAC,CAAC;IAC7D,OAAO,GAAG,CAAC;AACb,CAAC;AAED,qDAAqD;AACrD,MAAM,UAAU,aAAa,CAAC,IAAiB,EAAE,GAAY;IAC3D,OAAO,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,EAAoB,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC;AAC1E,CAAC"}