Skip to content

Pal API

import { createPal, createPalCore } from 'pagepal';
const pal = createPal(options); // every watcher available (Pal)
const core = createPalCore(options); // no watchers; add via plugins (PalCore)

Pal extends PalCore with the watch* convenience methods. Both are also exported as classes: new Pal(options).

MethodReturns
watch(target, options?)UnwatchWatch a form or container of forms. Forms
watchRequests(options?)Unwatchfetch and XHR. Requests
watchFetch(options?)Unwatchfetch only
watchXHR(options?)UnwatchXMLHttpRequest only
use(pluginOrWatcher)UnwatchAdd a plugin or a watcher from pagepal/watchers (available on PalCore)

Unwatch is a function: call it to stop watching.

MethodReturns
react(mood, ms?)thisShow a mood. Transient moods use their default duration; others hold. Infinity holds any mood
react(null)thisClear it
signal(key, mood, ms?)thisIndependent keyed signal; holds unless given a duration
clearSignal(key)this
say(text, ms = 2500)thisSpeech bubble (text only, never HTML)
lookAt(target, ms?)thisTurn toward an Element or { x, y } viewport point; null looks ahead
progress(value)thisProgress ring, 0..1, or null to hide

These methods return the pal, so they chain: pal.react('cheer').say('Saved!').

Member
hide()Hide for now (not remembered)
show()Show again, clearing a remembered dismissal
dismiss()Hide and remember it (what the ✕ does); emits dismiss
hiddenboolean
Member
moodThe mood currently shown
elementThe <pagepal-mascot> host element, or null on the server
on(event, listener)Subscribe to an event; returns an unsubscribe function
destroy()Remove the pal, stop every watcher and plugin, restore patched APIs
ExportFrom
blob, cat, ghost, defineCharacterpagepal, pagepal/charactersCharacters
DEFAULT_PRIORITIESpagepal, pagepal/coreThe default mood priorities
isDarkMode(document, window)pagepalThe built-in dark-mode detector
PagePalElementpagepal/elementThe <page-pal> class
debugPanel(options?)pagepal/debugDebug panel plugin

All types are exported from pagepal: Mood, TransientMood, PalOptions, PalCoreOptions, PalEvents, PalPlugin, PalPluginAPI, Watcher, Character, CharacterDefinition, CustomCharacter, FormTarget, WatchFormOptions, WatchRequestsOptions, FrustrationDetail, FormErrorDetail, FormSubmitDetail, FormProgressDetail, RequestDetail, ConnectionDetail, SignalInfo, Unwatch, and more.

The pal in the corner is pagepal itself.