@pie-players/pie-players-shared 0.3.73 → 0.3.75
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 +30 -2
- package/dist/components/vendor/nds/README.md +7 -5
- package/dist/config/profile.d.ts +0 -2
- package/dist/config/profile.js +2 -8
- package/dist/i18n/index.d.ts +2 -3
- package/dist/i18n/index.js +2 -3
- package/dist/i18n/messages/en-US.d.ts +11 -24
- package/dist/i18n/messages/en-US.js +13 -26
- package/dist/i18n/messages/nl-NL.d.ts +7 -24
- package/dist/i18n/messages/nl-NL.js +9 -26
- package/dist/i18n/provider.d.ts +4 -5
- package/dist/i18n/provider.js +4 -5
- package/dist/i18n/types.d.ts +4 -5
- package/dist/index.d.ts +4 -2
- package/dist/index.js +3 -1
- package/dist/instrumentation/index.d.ts +5 -4
- package/dist/instrumentation/index.js +5 -4
- package/dist/instrumentation/new-relic-agent.d.ts +20 -0
- package/dist/instrumentation/new-relic-agent.js +24 -0
- package/dist/instrumentation/providers/BaseInstrumentationProvider.d.ts +5 -4
- package/dist/instrumentation/providers/NewRelicInstrumentationProvider.d.ts +7 -7
- package/dist/instrumentation/providers/NewRelicInstrumentationProvider.js +21 -32
- package/dist/instrumentation/types.d.ts +7 -3
- package/dist/loader-config.d.ts +16 -6
- package/dist/loaders/controller-loading.d.ts +14 -0
- package/dist/loaders/controller-loading.js +12 -0
- package/dist/loaders/defaults.d.ts +10 -0
- package/dist/loaders/defaults.js +10 -0
- package/dist/loaders/element-loader.d.ts +20 -8
- package/dist/loaders/element-loader.js +102 -36
- package/dist/loaders/element-package-policy.d.ts +2 -0
- package/dist/loaders/element-package-policy.js +2 -1
- package/dist/loaders/esm-adapter.d.ts +29 -0
- package/dist/loaders/esm-adapter.js +635 -102
- package/dist/loaders/iife-adapter.d.ts +0 -5
- package/dist/loaders/iife-adapter.js +3 -9
- package/dist/loaders/index.d.ts +12 -3
- package/dist/loaders/index.js +9 -3
- package/dist/loaders/mathjax-events.d.ts +22 -0
- package/dist/loaders/mathjax-events.js +65 -0
- package/dist/loaders/module-shim.d.ts +12 -0
- package/dist/loaders/module-shim.js +12 -0
- package/dist/loaders/preloaded-alignment.d.ts +24 -0
- package/dist/loaders/preloaded-alignment.js +57 -0
- package/dist/loaders/preloaded-authored-tags.d.ts +26 -0
- package/dist/loaders/preloaded-authored-tags.js +69 -0
- package/dist/loaders/preloaded-registration.d.ts +72 -0
- package/dist/loaders/preloaded-registration.js +141 -0
- package/dist/media/index.d.ts +69 -0
- package/dist/media/index.js +194 -0
- package/dist/pie/authoring.d.ts +1 -1
- package/dist/pie/authoring.js +25 -18
- package/dist/pie/element-announcements.d.ts +39 -0
- package/dist/pie/element-announcements.js +67 -0
- package/dist/pie/element-observer.d.ts +3 -1
- package/dist/pie/element-observer.js +1 -0
- package/dist/pie/elements-rendered.d.ts +25 -0
- package/dist/pie/elements-rendered.js +96 -0
- package/dist/pie/index.d.ts +8 -10
- package/dist/pie/index.js +9 -10
- package/dist/pie/initialization.js +13 -22
- package/dist/pie/initialize-element.d.ts +3 -0
- package/dist/pie/initialize-element.js +3 -4
- package/dist/pie/instrumentation-event-bridge.js +23 -1
- package/dist/pie/instrumentation-event-map.js +11 -25
- package/dist/pie/instrumentation-provider-resolution.d.ts +2 -1
- package/dist/pie/instrumentation-provider-resolution.js +0 -1
- package/dist/pie/item-controller.js +4 -0
- package/dist/pie/item-session-contract.d.ts +8 -0
- package/dist/pie/item-session-contract.js +30 -9
- package/dist/pie/logger.d.ts +6 -0
- package/dist/pie/logger.js +10 -0
- package/dist/pie/markup-math.d.ts +20 -0
- package/dist/pie/markup-math.js +118 -0
- package/dist/pie/math-assets.d.ts +48 -0
- package/dist/pie/math-assets.js +81 -0
- package/dist/pie/math-rendering.d.ts +10 -21
- package/dist/pie/math-rendering.js +50 -35
- package/dist/pie/registry.d.ts +13 -1
- package/dist/pie/registry.js +39 -1
- package/dist/pie/resource-monitor.d.ts +6 -33
- package/dist/pie/resource-monitor.js +14 -213
- package/dist/pie/scoring.d.ts +12 -8
- package/dist/pie/scoring.js +21 -24
- package/dist/pie/session-commit.d.ts +16 -0
- package/dist/pie/session-commit.js +34 -6
- package/dist/pie/session-snapshot.d.ts +80 -0
- package/dist/pie/session-snapshot.js +166 -0
- package/dist/pie/stages.d.ts +10 -47
- package/dist/pie/stages.js +10 -47
- package/dist/pie/tag-names.d.ts +1 -0
- package/dist/pie/tag-names.js +1 -0
- package/dist/pie/types.d.ts +4 -5
- package/dist/pie/types.js +1 -0
- package/dist/pie/updates.d.ts +2 -2
- package/dist/pie/updates.js +33 -15
- package/dist/pie/versioned-tag.d.ts +4 -0
- package/dist/pie/versioned-tag.js +4 -0
- package/dist/security/index.d.ts +2 -3
- package/dist/security/index.js +2 -3
- package/dist/security/sanitize-item-markup.d.ts +4 -2
- package/dist/security/sanitize-item-markup.js +48 -6
- package/dist/security/sanitize-svg-icon.d.ts +0 -2
- package/dist/security/sanitize-svg-icon.js +0 -5
- package/dist/security/wrap-overwide-images.js +19 -0
- package/dist/security/wrap-overwide.d.ts +13 -0
- package/dist/security/wrap-overwide.js +63 -3
- package/dist/timed-media/policy.js +5 -16
- package/dist/types/index.d.ts +67 -423
- package/dist/types/index.js +0 -68
- package/dist/ui/attribute-coercion.d.ts +12 -0
- package/dist/ui/attribute-coercion.js +33 -0
- package/dist/ui/content-styles.d.ts +18 -16
- package/dist/ui/content-styles.js +67 -36
- package/dist/ui/overlay-containment.d.ts +31 -0
- package/dist/ui/overlay-containment.js +63 -0
- package/dist/ui/overlay-placement.d.ts +110 -0
- package/dist/ui/overlay-placement.js +222 -0
- package/dist/ui/pointer-gesture.d.ts +32 -0
- package/dist/ui/pointer-gesture.js +56 -0
- package/dist/ui/pointer-rotate.d.ts +29 -0
- package/dist/ui/pointer-rotate.js +39 -0
- package/package.json +23 -18
- package/dist/pie/component-context.d.ts +0 -21
- package/dist/pie/component-context.js +0 -29
- package/dist/pie/player-initializer.d.ts +0 -54
- package/dist/pie/player-initializer.js +0 -122
- package/dist/pie/stage-tracker.d.ts +0 -50
- package/dist/pie/stage-tracker.js +0 -105
- package/dist/security/wrap-model-rich-content.d.ts +0 -1
- package/dist/security/wrap-model-rich-content.js +0 -40
- package/dist/server/npm-auth-env.d.ts +0 -13
- package/dist/server/npm-auth-env.js +0 -64
- package/dist/server/npm-registry.d.ts +0 -7
- package/dist/server/npm-registry.js +0 -59
- package/dist/ui/debug-panel-persistence.d.ts +0 -17
- package/dist/ui/debug-panel-persistence.js +0 -37
|
@@ -1,122 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared PIE player initialization logic
|
|
3
|
-
* Used by preloaded static player runtimes
|
|
4
|
-
*/
|
|
5
|
-
/**
|
|
6
|
-
* Initialize PIE player with item data
|
|
7
|
-
* Shared initialization for preloaded/static player entrypoints.
|
|
8
|
-
*/
|
|
9
|
-
export async function initializePiePlayer(itemData, config, elements) {
|
|
10
|
-
const { playerEl } = elements;
|
|
11
|
-
if (!itemData.item?.config || !playerEl) {
|
|
12
|
-
throw new Error("Missing item config or player element");
|
|
13
|
-
}
|
|
14
|
-
// Ensure pie-player is loaded
|
|
15
|
-
await ensurePiePlayerLoaded();
|
|
16
|
-
const defaultEnv = config.env || { mode: "evaluate", role: "instructor" };
|
|
17
|
-
// Configure player element
|
|
18
|
-
playerEl.config = itemData.item.config;
|
|
19
|
-
playerEl.env = defaultEnv;
|
|
20
|
-
const shouldShowCorrect = !!(config.addCorrectResponse ||
|
|
21
|
-
(defaultEnv.mode === "evaluate" && defaultEnv.role === "instructor"));
|
|
22
|
-
playerEl.addCorrectResponse = shouldShowCorrect;
|
|
23
|
-
// Forward additional properties
|
|
24
|
-
playerEl.session = {
|
|
25
|
-
id: "",
|
|
26
|
-
data: Array.isArray(config.session) ? config.session : [],
|
|
27
|
-
};
|
|
28
|
-
if (config.externalStyleUrls) {
|
|
29
|
-
playerEl.externalStyleUrls = config.externalStyleUrls;
|
|
30
|
-
}
|
|
31
|
-
if (config.customClassName) {
|
|
32
|
-
playerEl.customClassName = config.customClassName;
|
|
33
|
-
}
|
|
34
|
-
if (config.containerClass) {
|
|
35
|
-
playerEl.containerClass = config.containerClass;
|
|
36
|
-
}
|
|
37
|
-
if (config.passageContainerClass) {
|
|
38
|
-
playerEl.passageContainerClass = config.passageContainerClass;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Extract passage markup from item data
|
|
43
|
-
*/
|
|
44
|
-
export function extractPassageMarkup(itemData) {
|
|
45
|
-
return itemData.passage?.config?.markup || null;
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Ensure pie-player web component is loaded
|
|
49
|
-
*/
|
|
50
|
-
export async function ensurePiePlayerLoaded() {
|
|
51
|
-
if (customElements.get("pie-player"))
|
|
52
|
-
return;
|
|
53
|
-
const url = "https://cdn.jsdelivr.net/npm/@pie-players/pie-player-components@latest/dist/pie-player-components/pie-player-components.esm.js";
|
|
54
|
-
await new Promise((resolve, reject) => {
|
|
55
|
-
const existing = document.querySelector("script[data-pie-player]");
|
|
56
|
-
if (existing) {
|
|
57
|
-
existing.addEventListener("load", () => resolve());
|
|
58
|
-
existing.addEventListener("error", () => reject(new Error("failed to load pie-player")));
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const s = document.createElement("script");
|
|
62
|
-
s.type = "module";
|
|
63
|
-
s.dataset.piePlayer = "true";
|
|
64
|
-
s.src = url;
|
|
65
|
-
s.addEventListener("load", () => resolve());
|
|
66
|
-
s.addEventListener("error", () => reject(new Error("failed to load pie-player")));
|
|
67
|
-
document.head.appendChild(s);
|
|
68
|
-
});
|
|
69
|
-
await customElements.whenDefined("pie-player");
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Build event listeners map for PIE elements
|
|
73
|
-
*/
|
|
74
|
-
export function buildEventListenersMap(config, onSessionChanged) {
|
|
75
|
-
if (!config?.elements)
|
|
76
|
-
return undefined;
|
|
77
|
-
const listeners = {};
|
|
78
|
-
Object.keys(config.elements).forEach((elName) => {
|
|
79
|
-
listeners[elName] = {
|
|
80
|
-
"session-changed": (e) => onSessionChanged(e.detail),
|
|
81
|
-
};
|
|
82
|
-
});
|
|
83
|
-
return listeners;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Build URL parameters for API request
|
|
87
|
-
* Shared by preloaded/static player entrypoints.
|
|
88
|
-
*/
|
|
89
|
-
export function buildApiParams(env, addCorrectResponse) {
|
|
90
|
-
const params = new URLSearchParams();
|
|
91
|
-
if (env && typeof env === "object") {
|
|
92
|
-
if (env.mode)
|
|
93
|
-
params.set("mode", String(env.mode));
|
|
94
|
-
if (env.role)
|
|
95
|
-
params.set("role", String(env.role));
|
|
96
|
-
}
|
|
97
|
-
if (addCorrectResponse)
|
|
98
|
-
params.set("addCorrectResponse", "true");
|
|
99
|
-
return params;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* Fetch item data from API
|
|
103
|
-
* Shared by preloaded/static player entrypoints.
|
|
104
|
-
*/
|
|
105
|
-
export async function fetchItemData(apiBaseUrl, itemId, token, endpoint, env, addCorrectResponse, signal) {
|
|
106
|
-
if (typeof window === "undefined" || typeof document === "undefined") {
|
|
107
|
-
throw new Error("PIE initialization must run in browser");
|
|
108
|
-
}
|
|
109
|
-
const params = buildApiParams(env, addCorrectResponse);
|
|
110
|
-
const apiUrl = `${apiBaseUrl}/api/item/${itemId}/${endpoint}${params.toString() ? `?${params.toString()}` : ""}`;
|
|
111
|
-
const response = await fetch(apiUrl, {
|
|
112
|
-
headers: {
|
|
113
|
-
Authorization: `Bearer ${token}`,
|
|
114
|
-
Accept: "application/json",
|
|
115
|
-
},
|
|
116
|
-
signal,
|
|
117
|
-
});
|
|
118
|
-
if (!response.ok) {
|
|
119
|
-
throw new Error(`Failed to fetch item data: ${response.statusText}`);
|
|
120
|
-
}
|
|
121
|
-
return await response.json();
|
|
122
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { type Stage, type StageChangeDetail, type StageSourceCe, type StageStatus } from "./stages.js";
|
|
2
|
-
/**
|
|
3
|
-
* Stage tracker primitive (M6).
|
|
4
|
-
*
|
|
5
|
-
* One tracker per CE instance per cohort. `enter(stage, status?)` is the
|
|
6
|
-
* only mutation; `reset()` rolls the cohort over (e.g. when
|
|
7
|
-
* `(sectionId, attemptId)` changes).
|
|
8
|
-
*
|
|
9
|
-
* The tracker enforces the locked invariants from
|
|
10
|
-
* `m6_ready_vocab_canonical_followup.plan.md` §3.1–§3.6:
|
|
11
|
-
* - Monotonic ordering across `STAGES`. Backward transitions inside one
|
|
12
|
-
* cohort are rejected (dev) / warned-once (prod) so subscribers never
|
|
13
|
-
* see a stage regress without an intervening `reset()`.
|
|
14
|
-
* - Per-CE applicability. The post-retro canonical list applies to
|
|
15
|
-
* every CE shape; the `applicableStages` indirection is kept so a
|
|
16
|
-
* future shape-specific stage can opt out without rewriting callers.
|
|
17
|
-
* Non-applicable stages auto-emit `status: "skipped"` when an
|
|
18
|
-
* applicable later stage is entered, so iteration order stays stable
|
|
19
|
-
* across CE shapes.
|
|
20
|
-
* - One source for every emit. The injected `emit(detail)` function
|
|
21
|
-
* drives DOM events, engine subscribers, and coordinator subscribers
|
|
22
|
-
* from the same call site so no surface drifts.
|
|
23
|
-
*
|
|
24
|
-
* Failure semantics intentionally piggyback on the M3 framework-error
|
|
25
|
-
* contract: `enter(stage, "failed")` records the position; the
|
|
26
|
-
* framework error records the cause.
|
|
27
|
-
*/
|
|
28
|
-
export type CreateStageTrackerOptions = {
|
|
29
|
-
sourceCe: string;
|
|
30
|
-
sourceCeShape: StageSourceCe;
|
|
31
|
-
runtimeId: string;
|
|
32
|
-
sectionId?: string;
|
|
33
|
-
attemptId?: string;
|
|
34
|
-
emit: (detail: StageChangeDetail) => void;
|
|
35
|
-
now?: () => string;
|
|
36
|
-
onUnexpectedTransition?: (info: {
|
|
37
|
-
from: Stage | null;
|
|
38
|
-
to: Stage;
|
|
39
|
-
reason: "backward" | "duplicate";
|
|
40
|
-
}) => void;
|
|
41
|
-
};
|
|
42
|
-
export type StageTracker = {
|
|
43
|
-
enter: (stage: Stage, status?: StageStatus) => void;
|
|
44
|
-
reset: (next?: {
|
|
45
|
-
sectionId?: string;
|
|
46
|
-
attemptId?: string;
|
|
47
|
-
}) => void;
|
|
48
|
-
getCurrent: () => Stage | null;
|
|
49
|
-
};
|
|
50
|
-
export declare function createStageTracker(opts: CreateStageTrackerOptions): StageTracker;
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { STAGES, applicableStages, stageOrdinal, } from "./stages.js";
|
|
2
|
-
let unexpectedTransitionWarned = false;
|
|
3
|
-
function defaultUnexpectedTransitionLogger(info) {
|
|
4
|
-
if (unexpectedTransitionWarned)
|
|
5
|
-
return;
|
|
6
|
-
unexpectedTransitionWarned = true;
|
|
7
|
-
if (typeof console !== "undefined" && console.warn) {
|
|
8
|
-
console.warn(`[pie-stage-tracker] Unexpected ${info.reason} stage transition ` +
|
|
9
|
-
`from \`${info.from ?? "<none>"}\` to \`${info.to}\`. ` +
|
|
10
|
-
`Stage transitions are expected to be monotonic within a cohort; ` +
|
|
11
|
-
`call \`reset()\` when \`(sectionId, attemptId)\` changes.`);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
export function createStageTracker(opts) {
|
|
15
|
-
const applicable = applicableStages(opts.sourceCeShape);
|
|
16
|
-
const applicableSet = new Set(applicable);
|
|
17
|
-
const now = opts.now ?? (() => new Date().toISOString());
|
|
18
|
-
const onUnexpected = opts.onUnexpectedTransition ?? defaultUnexpectedTransitionLogger;
|
|
19
|
-
let current = null;
|
|
20
|
-
let sectionId = opts.sectionId;
|
|
21
|
-
let attemptId = opts.attemptId;
|
|
22
|
-
const emitted = new Set();
|
|
23
|
-
function emitDetail(stage, status) {
|
|
24
|
-
opts.emit({
|
|
25
|
-
stage,
|
|
26
|
-
status,
|
|
27
|
-
runtimeId: opts.runtimeId,
|
|
28
|
-
sectionId,
|
|
29
|
-
attemptId,
|
|
30
|
-
timestamp: now(),
|
|
31
|
-
sourceCe: opts.sourceCe,
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
function fillSkippedBefore(stage) {
|
|
35
|
-
const targetIdx = stageOrdinal(stage);
|
|
36
|
-
const startIdx = current === null ? 0 : stageOrdinal(current) + 1;
|
|
37
|
-
for (let idx = startIdx; idx < targetIdx; idx += 1) {
|
|
38
|
-
const skipCandidate = STAGES[idx];
|
|
39
|
-
if (applicableSet.has(skipCandidate))
|
|
40
|
-
continue;
|
|
41
|
-
if (emitted.has(skipCandidate))
|
|
42
|
-
continue;
|
|
43
|
-
emitted.add(skipCandidate);
|
|
44
|
-
emitDetail(skipCandidate, "skipped");
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
function enter(stage, status = "entered") {
|
|
48
|
-
const nextOrdinal = stageOrdinal(stage);
|
|
49
|
-
const currentOrdinal = current === null ? -1 : stageOrdinal(current);
|
|
50
|
-
if (status === "entered") {
|
|
51
|
-
if (emitted.has(stage)) {
|
|
52
|
-
onUnexpected({ from: current, to: stage, reason: "duplicate" });
|
|
53
|
-
return;
|
|
54
|
-
}
|
|
55
|
-
if (nextOrdinal < currentOrdinal) {
|
|
56
|
-
onUnexpected({ from: current, to: stage, reason: "backward" });
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
if (!applicableSet.has(stage)) {
|
|
60
|
-
// A non-applicable stage entered with `entered` is a programming
|
|
61
|
-
// error: the tracker auto-skips it when a later stage enters.
|
|
62
|
-
// Treat it as a `skipped` emission and continue.
|
|
63
|
-
if (emitted.has(stage))
|
|
64
|
-
return;
|
|
65
|
-
emitted.add(stage);
|
|
66
|
-
emitDetail(stage, "skipped");
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
fillSkippedBefore(stage);
|
|
70
|
-
emitted.add(stage);
|
|
71
|
-
current = stage;
|
|
72
|
-
emitDetail(stage, "entered");
|
|
73
|
-
return;
|
|
74
|
-
}
|
|
75
|
-
// `status === "failed"` records position; do not gate on monotonic
|
|
76
|
-
// ordering — failure can happen during any transition. Mark the stage
|
|
77
|
-
// as emitted so a subsequent `entered` for the same stage warns as a
|
|
78
|
-
// duplicate; downstream recovery should call `reset()` first.
|
|
79
|
-
if (status === "failed") {
|
|
80
|
-
fillSkippedBefore(stage);
|
|
81
|
-
emitted.add(stage);
|
|
82
|
-
current = stage;
|
|
83
|
-
emitDetail(stage, "failed");
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
// `status === "skipped"` is reserved for the auto-fill path; explicit
|
|
87
|
-
// callers shouldn't pass it. Accept it idempotently for robustness.
|
|
88
|
-
if (emitted.has(stage))
|
|
89
|
-
return;
|
|
90
|
-
emitted.add(stage);
|
|
91
|
-
emitDetail(stage, "skipped");
|
|
92
|
-
}
|
|
93
|
-
function reset(next) {
|
|
94
|
-
current = null;
|
|
95
|
-
emitted.clear();
|
|
96
|
-
if (next) {
|
|
97
|
-
sectionId = next.sectionId;
|
|
98
|
-
attemptId = next.attemptId;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
function getCurrent() {
|
|
102
|
-
return current;
|
|
103
|
-
}
|
|
104
|
-
return { enter, reset, getCurrent };
|
|
105
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function wrapModelRichContent<T>(model: T): T;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { wrapOverwideImages } from "./wrap-overwide-images.js";
|
|
2
|
-
import { wrapOverwideTables } from "./wrap-overwide-tables.js";
|
|
3
|
-
const RICH_CONTENT_TAG_REGEX = /<(?:img|table)\b/i;
|
|
4
|
-
const SKIPPED_KEYS = new Set(["accessibilityCatalogs"]);
|
|
5
|
-
function maybeWrapRichContent(value) {
|
|
6
|
-
if (!RICH_CONTENT_TAG_REGEX.test(value))
|
|
7
|
-
return value;
|
|
8
|
-
return wrapOverwideTables(wrapOverwideImages(value));
|
|
9
|
-
}
|
|
10
|
-
function wrapValue(value, parentKey) {
|
|
11
|
-
if (parentKey && SKIPPED_KEYS.has(parentKey))
|
|
12
|
-
return value;
|
|
13
|
-
if (typeof value === "string")
|
|
14
|
-
return maybeWrapRichContent(value);
|
|
15
|
-
if (!value || typeof value !== "object")
|
|
16
|
-
return value;
|
|
17
|
-
if (Array.isArray(value)) {
|
|
18
|
-
let changed = false;
|
|
19
|
-
const next = value.map((entry) => {
|
|
20
|
-
const wrapped = wrapValue(entry);
|
|
21
|
-
if (wrapped !== entry)
|
|
22
|
-
changed = true;
|
|
23
|
-
return wrapped;
|
|
24
|
-
});
|
|
25
|
-
return changed ? next : value;
|
|
26
|
-
}
|
|
27
|
-
const record = value;
|
|
28
|
-
let changed = false;
|
|
29
|
-
const next = {};
|
|
30
|
-
for (const [key, entry] of Object.entries(record)) {
|
|
31
|
-
const wrapped = wrapValue(entry, key);
|
|
32
|
-
if (wrapped !== entry)
|
|
33
|
-
changed = true;
|
|
34
|
-
next[key] = wrapped;
|
|
35
|
-
}
|
|
36
|
-
return changed ? next : value;
|
|
37
|
-
}
|
|
38
|
-
export function wrapModelRichContent(model) {
|
|
39
|
-
return wrapValue(model);
|
|
40
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Write a temp `.npmrc` carrying a scoped `_authToken` and return an env
|
|
3
|
-
* object pointing `NPM_CONFIG_USERCONFIG` at it, so a publish subprocess
|
|
4
|
-
* authenticates without a separate `npm login`. The token comes from
|
|
5
|
-
* `NPM_TOKEN`/`NODE_AUTH_TOKEN` in `baseEnv` first, falling back to parsing
|
|
6
|
-
* an `.env`-style file at `envPath` for either key.
|
|
7
|
-
*
|
|
8
|
-
* Call `cleanup()` once the subprocess using `env` has exited.
|
|
9
|
-
*/
|
|
10
|
-
export declare const createNpmAuthEnvironment: (envPath?: string, baseEnv?: NodeJS.ProcessEnv) => {
|
|
11
|
-
env: NodeJS.ProcessEnv;
|
|
12
|
-
cleanup: () => void;
|
|
13
|
-
};
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { tmpdir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
if (typeof window !== "undefined") {
|
|
5
|
-
throw new Error("[npm-auth-env] @pie-players/pie-players-shared/server/npm-auth-env is server-only and cannot be imported in browser code");
|
|
6
|
-
}
|
|
7
|
-
const REGISTRY = "https://registry.npmjs.org/";
|
|
8
|
-
const parseDotEnvToken = (envPath, key) => {
|
|
9
|
-
try {
|
|
10
|
-
const content = readFileSync(envPath, "utf8");
|
|
11
|
-
const pattern = new RegExp(`^\\s*(?:export\\s+)?${key}\\s*=\\s*(.*)\\s*$`, "m");
|
|
12
|
-
const match = content.match(pattern);
|
|
13
|
-
if (!match?.[1])
|
|
14
|
-
return "";
|
|
15
|
-
const rawValue = match[1].trim();
|
|
16
|
-
const isWrappedInQuotes = (rawValue.startsWith('"') && rawValue.endsWith('"')) ||
|
|
17
|
-
(rawValue.startsWith("'") && rawValue.endsWith("'"));
|
|
18
|
-
return (isWrappedInQuotes ? rawValue.slice(1, -1) : rawValue).trim();
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
return "";
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const resolveToken = (envPath, baseEnv) => {
|
|
25
|
-
const envToken = String(baseEnv.NPM_TOKEN || baseEnv.NODE_AUTH_TOKEN || "").trim();
|
|
26
|
-
if (envToken)
|
|
27
|
-
return envToken;
|
|
28
|
-
if (!envPath)
|
|
29
|
-
return "";
|
|
30
|
-
return (parseDotEnvToken(envPath, "NPM_TOKEN") ||
|
|
31
|
-
parseDotEnvToken(envPath, "NODE_AUTH_TOKEN"));
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* Write a temp `.npmrc` carrying a scoped `_authToken` and return an env
|
|
35
|
-
* object pointing `NPM_CONFIG_USERCONFIG` at it, so a publish subprocess
|
|
36
|
-
* authenticates without a separate `npm login`. The token comes from
|
|
37
|
-
* `NPM_TOKEN`/`NODE_AUTH_TOKEN` in `baseEnv` first, falling back to parsing
|
|
38
|
-
* an `.env`-style file at `envPath` for either key.
|
|
39
|
-
*
|
|
40
|
-
* Call `cleanup()` once the subprocess using `env` has exited.
|
|
41
|
-
*/
|
|
42
|
-
export const createNpmAuthEnvironment = (envPath, baseEnv = process.env) => {
|
|
43
|
-
const token = resolveToken(envPath, baseEnv);
|
|
44
|
-
if (!token) {
|
|
45
|
-
return {
|
|
46
|
-
env: baseEnv,
|
|
47
|
-
cleanup: () => { },
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
const tempDir = mkdtempSync(join(tmpdir(), "pie-npm-auth-"));
|
|
51
|
-
const npmrcPath = join(tempDir, ".npmrc");
|
|
52
|
-
writeFileSync(npmrcPath, `registry=${REGISTRY}\n//registry.npmjs.org/:_authToken=${token}\n`, "utf8");
|
|
53
|
-
return {
|
|
54
|
-
env: {
|
|
55
|
-
...baseEnv,
|
|
56
|
-
NPM_CONFIG_USERCONFIG: npmrcPath,
|
|
57
|
-
NODE_AUTH_TOKEN: String(baseEnv.NODE_AUTH_TOKEN || "").trim() || token,
|
|
58
|
-
NPM_TOKEN: String(baseEnv.NPM_TOKEN || "").trim() || token,
|
|
59
|
-
},
|
|
60
|
-
cleanup: () => {
|
|
61
|
-
rmSync(tempDir, { recursive: true, force: true });
|
|
62
|
-
},
|
|
63
|
-
};
|
|
64
|
-
};
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
type NpmFetch = (input: RequestInfo | URL, init?: RequestInit) => Promise<Response>;
|
|
2
|
-
/**
|
|
3
|
-
* Server-only helper for npm package version lookups.
|
|
4
|
-
* Do not import this module from browser-executed code.
|
|
5
|
-
*/
|
|
6
|
-
export declare const getNpmPackageVersions: (element: string, fetch: NpmFetch, filter?: (v: string) => boolean, limit?: number, searchTerm?: string) => Promise<string[]>;
|
|
7
|
-
export {};
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import semver from "semver";
|
|
2
|
-
const NPM_REGISTRY_URL = "https://registry.npmjs.org";
|
|
3
|
-
if (typeof window !== "undefined") {
|
|
4
|
-
throw new Error("[npm-registry] @pie-players/pie-players-shared/server/npm-registry is server-only and cannot be imported in browser code");
|
|
5
|
-
}
|
|
6
|
-
const DEFAULT_FILTER = (v) => v.indexOf("print") === -1 &&
|
|
7
|
-
v.indexOf("ps") === -1 &&
|
|
8
|
-
v.indexOf("strikethrough") === -1 &&
|
|
9
|
-
v.indexOf("alpha") === -1 &&
|
|
10
|
-
v.indexOf("bm") === -1;
|
|
11
|
-
/**
|
|
12
|
-
* Server-only helper for npm package version lookups.
|
|
13
|
-
* Do not import this module from browser-executed code.
|
|
14
|
-
*/
|
|
15
|
-
export const getNpmPackageVersions = async (element, fetch, filter = DEFAULT_FILTER, limit, searchTerm = "") => {
|
|
16
|
-
if (typeof window !== "undefined") {
|
|
17
|
-
throw new Error("[npm-registry] server-only module imported in browser context");
|
|
18
|
-
}
|
|
19
|
-
try {
|
|
20
|
-
const response = await fetch(`${NPM_REGISTRY_URL}/${element}`);
|
|
21
|
-
if (!response.ok) {
|
|
22
|
-
console.warn(`[npm-registry] npm status ${response.status} for package ${element}`);
|
|
23
|
-
return searchTerm ? [] : ["latest"];
|
|
24
|
-
}
|
|
25
|
-
const json = await response.json();
|
|
26
|
-
const versions = json?.versions;
|
|
27
|
-
if (!versions || typeof versions !== "object") {
|
|
28
|
-
console.warn(`[npm-registry] response for ${element} missing 'versions' property`);
|
|
29
|
-
return searchTerm ? [] : ["latest"];
|
|
30
|
-
}
|
|
31
|
-
let sorted = Object.keys(versions)
|
|
32
|
-
.filter(filter)
|
|
33
|
-
.filter((v) => !versions[v]?.deprecated)
|
|
34
|
-
.filter((v) => !/^11\.0\.\d+-esm\.\d+/.test(v))
|
|
35
|
-
.filter((v) => !searchTerm || v.toLowerCase().includes(searchTerm.toLowerCase()))
|
|
36
|
-
.sort((a, b) => {
|
|
37
|
-
const verA = semver.valid(semver.clean(a));
|
|
38
|
-
const verB = semver.valid(semver.clean(b));
|
|
39
|
-
if (!verA && !verB)
|
|
40
|
-
return 0;
|
|
41
|
-
if (!verA)
|
|
42
|
-
return 1;
|
|
43
|
-
if (!verB)
|
|
44
|
-
return -1;
|
|
45
|
-
return semver.rcompare(verA, verB);
|
|
46
|
-
});
|
|
47
|
-
if (typeof limit === "number" && limit > 0) {
|
|
48
|
-
sorted = sorted.slice(0, limit);
|
|
49
|
-
}
|
|
50
|
-
if (!searchTerm) {
|
|
51
|
-
sorted.unshift("latest");
|
|
52
|
-
}
|
|
53
|
-
return sorted;
|
|
54
|
-
}
|
|
55
|
-
catch (error) {
|
|
56
|
-
console.warn(`[npm-registry] failed package lookup for ${element}:`, error);
|
|
57
|
-
return searchTerm ? [] : ["latest"];
|
|
58
|
-
}
|
|
59
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
type DebugPanelStorageKeyArgs = {
|
|
2
|
-
scope: string;
|
|
3
|
-
panelId: string;
|
|
4
|
-
aspect?: string;
|
|
5
|
-
};
|
|
6
|
-
export declare function createDebugPanelStorageKey(args: DebugPanelStorageKeyArgs): string;
|
|
7
|
-
export declare function readDebugPanelState<T>(key: string): T | null;
|
|
8
|
-
export declare function writeDebugPanelState<T>(key: string, value: T): void;
|
|
9
|
-
export declare function clearDebugPanelState(key: string): void;
|
|
10
|
-
export type DebugPanelLayoutStateV1 = {
|
|
11
|
-
x: number;
|
|
12
|
-
y: number;
|
|
13
|
-
width: number;
|
|
14
|
-
height: number;
|
|
15
|
-
minimized: boolean;
|
|
16
|
-
};
|
|
17
|
-
export {};
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { safeLocalStorageGet, safeLocalStorageSet } from "./safe-storage.js";
|
|
2
|
-
const DEBUG_PANEL_STORAGE_PREFIX = "pie:debug-panels:v1";
|
|
3
|
-
export function createDebugPanelStorageKey(args) {
|
|
4
|
-
const scope = String(args.scope || "default").trim() || "default";
|
|
5
|
-
const panelId = String(args.panelId || "panel").trim() || "panel";
|
|
6
|
-
const aspect = String(args.aspect || "state").trim() || "state";
|
|
7
|
-
return `${DEBUG_PANEL_STORAGE_PREFIX}:${scope}:${panelId}:${aspect}`;
|
|
8
|
-
}
|
|
9
|
-
export function readDebugPanelState(key) {
|
|
10
|
-
const raw = safeLocalStorageGet(key);
|
|
11
|
-
if (!raw)
|
|
12
|
-
return null;
|
|
13
|
-
try {
|
|
14
|
-
return JSON.parse(raw);
|
|
15
|
-
}
|
|
16
|
-
catch {
|
|
17
|
-
return null;
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
export function writeDebugPanelState(key, value) {
|
|
21
|
-
try {
|
|
22
|
-
safeLocalStorageSet(key, JSON.stringify(value));
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
// ignore serialization/storage failures
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
export function clearDebugPanelState(key) {
|
|
29
|
-
try {
|
|
30
|
-
if (typeof localStorage === "undefined")
|
|
31
|
-
return;
|
|
32
|
-
localStorage.removeItem(key);
|
|
33
|
-
}
|
|
34
|
-
catch {
|
|
35
|
-
// ignore
|
|
36
|
-
}
|
|
37
|
-
}
|