Repository navigation
add tests, typescript, and improve pager/next chapter #65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nschimme
merged 15 commits into
MUME:master
from
nschimme:fix-tutorial-pager-scroll-15358760155283308909
Sep 21, 2026
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2115e0f
fix(tutorial): improve pager overflow detection and scroll positioning
nschimme 11e92a0
fix(tutorial): improve pager overflow detection, image loading, and s…
nschimme 3255859
fix(tutorial): improve pager overflow, image loading, and scroll posi…
nschimme d1c6c84
fix(tutorial): improve pager overflow, image loading, and scroll posi…
nschimme 2ae9b26
fix(tutorial): improve pager overflow, image loading, and scroll posi…
nschimme cdf1d5e
fix(tutorial): improve terminal pagination and mobile touch UX
nschimme ecae955
fix(tutorial): enable scroll-to-top and pager for chapter intro content
nschimme a05eaef
fix(tutorial): implement state machine for pager transitions and impr…
nschimme a8a55c2
fix(tutorial): normalize Chapter Complete prompt bar UX and state tra…
nschimme dd49ba1
Fix tutorial player output pagination and top scroll alignment
nschimme 6baad6f
fix: resolve tutorial output pagination, scroll alignment, and prompt…
nschimme 66e3bbf
fix: resolve tutorial output pagination and polish chapter completion…
nschimme ff73c02
fix(tutorial): introduce pager state machine & improve overflow scrol…
nschimme 2e64d74
fix(tutorial): refine markdown link escaping and scroll completion de…
nschimme 69767bd
fix(tutorial): ensure Enter key advances pagination and chapter compl…
nschimme File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /** | ||
| * Utility functions for inline markdown formatting in tutorial elements. | ||
| */ | ||
|
|
||
| export type WithBaseFn = (url: string) => string | ||
|
|
||
| /** | ||
| * Formats inline markdown strings into HTML safely. | ||
| * Supports: | ||
| * - HTML entity escaping for & < > | ||
| * - Embedded images:  with lazy loading, aspect ratio placeholders, and lightbox triggers | ||
| * - Links: [text](url) | ||
| * - Bold: **text** or __text__ | ||
| * - Italics: *text* or _text_ | ||
| * - Inline code: `code` | ||
| * - Line breaks: \n -> <br> | ||
| */ | ||
| export function formatInlineMarkdown(text: string | null | undefined, withBaseFn: WithBaseFn = (url) => url): string { | ||
| if (!text) return '' | ||
|
|
||
| // Escape HTML entities | ||
| let safe = text | ||
| .replace(/&/g, '&') | ||
| .replace(/</g, '<') | ||
| .replace(/>/g, '>') | ||
|
|
||
| // Images:  | ||
| safe = safe.replace(/!\[([^\]]*)\]\(([^)]+)\)/g, (_match, alt, src) => { | ||
| const cleanAlt = alt.replace(/"/g, '"') | ||
| let cleanSrc = src.trim().replace(/"/g, '"') | ||
|
|
||
| if (!/^(?:https?:\/\/|data:)/i.test(cleanSrc)) { | ||
| if (cleanSrc.includes('assets/')) { | ||
| cleanSrc = '/assets/' + cleanSrc.split('assets/')[1] | ||
| } | ||
|
|
||
| if (cleanSrc.startsWith('/') && typeof withBaseFn === 'function') { | ||
| cleanSrc = withBaseFn(cleanSrc) | ||
| } | ||
| } | ||
|
|
||
| return `<span class="tut-img-container"><img src="${cleanSrc}" alt="${cleanAlt}" class="tut-img-embed" loading="lazy" onload="this.dispatchEvent(new Event('load', { bubbles: true }))" /></span>` | ||
| }) | ||
|
|
||
| // Links: [text](url) | ||
| safe = safe.replace(/\[([^\]]+)\]\(([^)]+)\)/g, (_match, linkText, url) => { | ||
| const cleanText = linkText | ||
| const trimmed = url.trim() | ||
|
|
||
| // Validate safe schemes: http, https, mailto, relative paths, or hash anchors | ||
| const isHttp = /^https?:\/\//i.test(trimmed) | ||
| const isMailto = /^mailto:/i.test(trimmed) | ||
| const isRelativeOrHash = /^(?:\/|\.\.|\.|\#)/.test(trimmed) | ||
|
|
||
| if (!isHttp && !isMailto && !isRelativeOrHash) { | ||
| return cleanText | ||
| } | ||
|
|
||
| let finalUrl = trimmed | ||
| if (finalUrl.startsWith('/') && typeof withBaseFn === 'function') { | ||
| finalUrl = withBaseFn(finalUrl) | ||
| } | ||
|
|
||
| // Escape URL for HTML attribute insertion | ||
| const escapedUrl = finalUrl | ||
| .replace(/"/g, '"') | ||
| .replace(/'/g, ''') | ||
| .replace(/</g, '<') | ||
| .replace(/>/g, '>') | ||
|
|
||
| return `<a href="${escapedUrl}" ${isHttp ? 'target="_blank" rel="noopener noreferrer"' : ''} class="tut-link">${cleanText}</a>` | ||
| }) | ||
|
|
||
| // Bold: **text** or __text__ | ||
| safe = safe.replace(/(\*\*|__)(.*?)\1/g, '<strong>$2</strong>') | ||
|
|
||
| // Italics: *text* or _text_ | ||
| safe = safe.replace(/(?<!\w)(\*|_)(.*?)\1(?!\w)/g, '<em>$2</em>') | ||
|
|
||
| // Code: `code` | ||
| safe = safe.replace(/`([^`]+)`/g, '<code class="tut-cmd-inline">$1</code>') | ||
|
|
||
| // Newlines | ||
| return safe.replace(/\n/g, '<br>') | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| /** | ||
| * Helper function to determine pager overflow state for scrollable containers. | ||
| * Uses sub-pixel tolerance to handle high-DPI displays and browser zoom. | ||
| */ | ||
|
|
||
| export function isOverflowActive( | ||
| container: HTMLElement | null, | ||
| scrollThreshold: number = 40, | ||
| remainingThreshold: number = 35 | ||
| ): boolean { | ||
| if (!container) return false | ||
| const scrollHeight = container.scrollHeight | ||
| const clientHeight = container.clientHeight | ||
| const scrollTop = container.scrollTop | ||
|
|
||
| const scrollableDistance = scrollHeight - clientHeight | ||
| // Use Math.ceil to protect against sub-pixel fractional scrolling discrepancies | ||
| const remainingScroll = scrollableDistance - Math.ceil(scrollTop) | ||
|
|
||
| return scrollableDistance > scrollThreshold && remainingScroll > remainingThreshold | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /** | ||
| * Utility functions for tutorial routing and chapter calculations. | ||
| */ | ||
|
|
||
| export enum PlayerState { | ||
| AWAITING_COMMAND = 'AWAITING_COMMAND', | ||
| PAGING_OUTPUT = 'PAGING_OUTPUT', | ||
| PLAYING_BEAT = 'PLAYING_BEAT', | ||
| CHAPTER_COMPLETE = 'CHAPTER_COMPLETE' | ||
| } | ||
|
|
||
| export interface Chapter { | ||
| chapterNum: number | ||
| title: string | ||
| url: string | ||
| filename: string | ||
| teach?: Array<{ command: string; desc: string }> | ||
| steps?: any[] | ||
| practice?: string | ||
| [key: string]: any | ||
| } | ||
|
|
||
| /** | ||
| * Normalizes route path to match chapter URLs, removing base prefix and trailing slashes. | ||
| */ | ||
| export function normalizeChapterPath(rawPath: string | undefined, basePrefix: string = '/'): string { | ||
| if (!rawPath) return '/' | ||
| let currentPath = rawPath.replace(/\.html$/, '').replace(/\/$/, '') | ||
| const base = basePrefix || '/' | ||
| const basePath = base.replace(/\/$/, '') | ||
| if (base !== '/' && basePath && (currentPath === basePath || currentPath.startsWith(basePath + '/'))) { | ||
| currentPath = '/' + currentPath.slice(basePath.length).replace(/^\//, '') | ||
| } | ||
| return currentPath || '/' | ||
| } | ||
|
|
||
| /** | ||
| * Finds current chapter object from all chapters list. | ||
| */ | ||
| export function findChapterByPath(chapters: Chapter[], normalizedPath: string): Chapter | null { | ||
| if (!chapters || !chapters.length) return null | ||
| return chapters.find(c => c.url === normalizedPath || normalizedPath.endsWith(c.filename)) || chapters[0] || null | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.