@hussmartinez/audio-sdk 0.6.0 → 0.7.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/dist/assets/audio/audio.worker.js +1 -1
- package/dist/element.d.ts +1010 -1
- package/dist/element.js +121 -0
- package/dist/element.js.map +1 -0
- package/dist/index.js +1 -2657
- package/dist/index.js.map +1 -1
- package/dist/lazy/inline-worker-CVcXmYih.js +30 -0
- package/dist/lazy/{inline-worker-D8bxbE-Q.js.map → inline-worker-CVcXmYih.js.map} +1 -1
- package/dist/react.d.ts +1957 -3
- package/dist/react.js +1 -0
- package/dist/shared/AudioEditor-C9yohR_Z.js +2801 -0
- package/dist/shared/AudioEditor-C9yohR_Z.js.map +1 -0
- package/dist/shared/text-CgDrmmTa.js +2663 -0
- package/dist/shared/text-CgDrmmTa.js.map +1 -0
- package/dist/styles.css +329 -0
- package/package.json +9 -5
- package/dist/lazy/inline-worker-D8bxbE-Q.js +0 -30
package/dist/element.js
CHANGED
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { l as ElementListenersContext, t as AudioEditor } from "./shared/AudioEditor-C9yohR_Z.js";
|
|
2
|
+
import { useEffect, useMemo, useRef } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import { createEditorElement } from "@hussmartinez/sdk-core/element";
|
|
5
|
+
import { createRoot } from "react-dom/client";
|
|
6
|
+
// src/react/element/mount.tsx
|
|
7
|
+
var MODES = /* @__PURE__ */ new Set([
|
|
8
|
+
"light",
|
|
9
|
+
"dark",
|
|
10
|
+
"system"
|
|
11
|
+
]);
|
|
12
|
+
function ElementEditor(props) {
|
|
13
|
+
const { values, setHandle, handle, dispatch } = props;
|
|
14
|
+
const { file, theme: _theme, ...editorProps } = values;
|
|
15
|
+
const opened = useRef(void 0);
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
if (!file || file === opened.current) return;
|
|
18
|
+
opened.current = file;
|
|
19
|
+
handle.current?.open(file).catch(() => {});
|
|
20
|
+
}, [file, handle]);
|
|
21
|
+
const listeners = useMemo(() => ({
|
|
22
|
+
onExport: (report) => dispatch("export", report),
|
|
23
|
+
onError: (error) => dispatch("error", error)
|
|
24
|
+
}), [dispatch]);
|
|
25
|
+
return /* @__PURE__ */ jsx(ElementListenersContext.Provider, {
|
|
26
|
+
value: listeners,
|
|
27
|
+
children: /* @__PURE__ */ jsx(AudioEditor, {
|
|
28
|
+
ref: setHandle,
|
|
29
|
+
...editorProps,
|
|
30
|
+
onChange: (plan) => dispatch("change", plan),
|
|
31
|
+
onEvent: (event) => dispatch("event", event)
|
|
32
|
+
})
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
function mountAudioEditor(host, initial, context) {
|
|
36
|
+
const root = createRoot(host);
|
|
37
|
+
const handle = { current: null };
|
|
38
|
+
let resolveReady = () => {};
|
|
39
|
+
const ready = new Promise((resolve) => {
|
|
40
|
+
resolveReady = resolve;
|
|
41
|
+
});
|
|
42
|
+
const setHandle = (editor) => {
|
|
43
|
+
handle.current = editor;
|
|
44
|
+
if (editor) resolveReady(editor);
|
|
45
|
+
};
|
|
46
|
+
const dispatch = context.dispatch;
|
|
47
|
+
const render = (values) => {
|
|
48
|
+
const mode = values.theme;
|
|
49
|
+
if (mode && MODES.has(mode)) host.setAttribute("data-hm-theme", mode);
|
|
50
|
+
else host.removeAttribute("data-hm-theme");
|
|
51
|
+
root.render(/* @__PURE__ */ jsx(ElementEditor, {
|
|
52
|
+
values,
|
|
53
|
+
setHandle,
|
|
54
|
+
handle,
|
|
55
|
+
dispatch
|
|
56
|
+
}));
|
|
57
|
+
};
|
|
58
|
+
render(initial);
|
|
59
|
+
const now = () => handle.current;
|
|
60
|
+
return {
|
|
61
|
+
update: render,
|
|
62
|
+
unmount: () => {
|
|
63
|
+
root.unmount();
|
|
64
|
+
host.removeAttribute("data-hm-theme");
|
|
65
|
+
},
|
|
66
|
+
handle: {
|
|
67
|
+
open: async (file) => (await ready).open(file),
|
|
68
|
+
insert: async (file, options) => (await ready).insert(file, options),
|
|
69
|
+
export: async (options) => (await ready).export(options),
|
|
70
|
+
undo: () => now()?.undo(),
|
|
71
|
+
redo: () => now()?.redo(),
|
|
72
|
+
play: async () => (await ready).play(),
|
|
73
|
+
pause: () => now()?.pause(),
|
|
74
|
+
seek: (frame) => now()?.seek(frame)
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
// src/element.ts
|
|
79
|
+
var words = (value) => value.split(/\s+/).filter(Boolean);
|
|
80
|
+
var defineAudioEditorElement = /* @__PURE__ */ createEditorElement({
|
|
81
|
+
kind: "audio",
|
|
82
|
+
attributes: {
|
|
83
|
+
theme: "theme",
|
|
84
|
+
locale: "locale",
|
|
85
|
+
tools: {
|
|
86
|
+
property: "tools",
|
|
87
|
+
parse: words
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
properties: [
|
|
91
|
+
"file",
|
|
92
|
+
"fileName",
|
|
93
|
+
"headingLevel",
|
|
94
|
+
"filePolicy",
|
|
95
|
+
"assetsUrl",
|
|
96
|
+
"messages",
|
|
97
|
+
"engine",
|
|
98
|
+
"processor",
|
|
99
|
+
"output"
|
|
100
|
+
],
|
|
101
|
+
methods: [
|
|
102
|
+
"open",
|
|
103
|
+
"insert",
|
|
104
|
+
"export",
|
|
105
|
+
"undo",
|
|
106
|
+
"redo",
|
|
107
|
+
"play",
|
|
108
|
+
"pause",
|
|
109
|
+
"seek"
|
|
110
|
+
],
|
|
111
|
+
events: [
|
|
112
|
+
"change",
|
|
113
|
+
"event",
|
|
114
|
+
"export",
|
|
115
|
+
"error"
|
|
116
|
+
],
|
|
117
|
+
mount: mountAudioEditor
|
|
118
|
+
});
|
|
119
|
+
export { defineAudioEditorElement };
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=element.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.js","names":[],"sources":["../src/react/element/mount.tsx","../src/element.ts"],"sourcesContent":["import type { EditorElementContext, MountedEditor } from \"@hussmartinez/sdk-core/element\";\nimport { type ReactNode, type RefCallback, useEffect, useMemo, useRef } from \"react\";\nimport { createRoot } from \"react-dom/client\";\nimport type { AudioFilePolicyOverrides } from \"../../core/errors/audio-limits.js\";\nimport type { AudioEngine } from \"../../core/ports/audio-engine.js\";\nimport type { AudioOutput } from \"../../core/ports/audio-output.js\";\nimport type { AudioProcessor } from \"../../core/ports/audio-processor.js\";\nimport { AudioEditor, type AudioEditorHandle } from \"../AudioEditor.js\";\nimport type { AudioHeadingLevel } from \"../AudioInspector.js\";\nimport type { AudioEditorMessageOverrides } from \"../editor-messages.js\";\nimport { type AudioExportReport, ElementListenersContext } from \"./listeners.js\";\n\n/**\n * The `<hm-audio-editor>` element's props: its attributes, `theme`, `locale`\n * and `tools`, and its properties (docs/adr/0005). They're writable, since a\n * host sets them on the element, such as `editor.file = file`.\n *\n * @public\n */\nexport interface AudioEditorElementProps {\n /** `light`, `dark` or `system`: ui's colour mode, on the element. Inherited when unset. */\n theme?: string;\n /** The locale for numbers and plurals. Defaults to `\"en\"`. */\n locale?: string;\n /** Which tools are present, by id, in order: the attribute is space-separated. */\n tools?: readonly string[];\n /** A recording to open. Setting another opens it, replacing the current one. */\n file?: Blob;\n /** The name an export is downloaded under, without its extension. */\n fileName?: string;\n /** The level of the editor's headings, from 2 to 6. Defaults to 2. */\n headingLevel?: AudioHeadingLevel;\n filePolicy?: AudioFilePolicyOverrides;\n /** Where the application serves the package's `dist/assets/` directory. */\n assetsUrl?: string | URL;\n /** Text overrides, typed against the English catalogue. */\n messages?: AudioEditorMessageOverrides;\n engine?: AudioEngine;\n processor?: AudioProcessor;\n output?: AudioOutput;\n}\n\n/**\n * The `<hm-audio-editor>` element's methods: the React editor's ref handle.\n * `open()`, `insert()` and `export()` wait for the editor's first render;\n * the others act on the editor there is, and do nothing before it.\n *\n * @public\n */\nexport type AudioEditorElementMethods = Pick<\n AudioEditorHandle,\n \"open\" | \"insert\" | \"export\" | \"undo\" | \"redo\" | \"play\" | \"pause\" | \"seek\"\n>;\n\n/**\n * The element's events, fired as `hm-audio-editor-<name>`. None carries a\n * file name or contents (sdk-core ADR 0012):\n *\n * - `change`: the plan, after each committed edit, open, undo or redo.\n * - `event`: the session's anonymous usage event.\n * - `export`: an {@link AudioExportReport} after the export dialog finishes.\n * - `error`: `{ code, details }` of a failure the editor shows.\n *\n * @public\n */\nexport type AudioEditorElementEvent = \"change\" | \"event\" | \"export\" | \"error\";\n\nconst MODES = new Set([\"light\", \"dark\", \"system\"]);\n\ninterface ElementEditorProps {\n readonly values: Partial<AudioEditorElementProps>;\n readonly setHandle: RefCallback<AudioEditorHandle>;\n readonly handle: { readonly current: AudioEditorHandle | null };\n readonly dispatch: EditorElementContext<AudioEditorElementEvent>[\"dispatch\"];\n}\n\nfunction ElementEditor(props: ElementEditorProps): ReactNode {\n const { values, setHandle, handle, dispatch } = props;\n const { file, theme: _theme, ...editorProps } = values;\n\n // A file opens when it's set, and another replaces it. A failure is the\n // editor's to show, and the element's `error` event.\n const opened = useRef<Blob | undefined>(undefined);\n useEffect(() => {\n if (!file || file === opened.current) return;\n opened.current = file;\n handle.current?.open(file).catch(() => {});\n }, [file, handle]);\n\n const listeners = useMemo(\n () => ({\n onExport: (report: AudioExportReport) => dispatch(\"export\", report),\n onError: (error: { code: string; details: Readonly<Record<string, unknown>> }) =>\n dispatch(\"error\", error),\n }),\n [dispatch],\n );\n\n return (\n <ElementListenersContext.Provider value={listeners}>\n <AudioEditor\n ref={setHandle}\n {...editorProps}\n onChange={(plan) => dispatch(\"change\", plan)}\n onEvent={(event) => dispatch(\"event\", event)}\n />\n </ElementListenersContext.Provider>\n );\n}\n\n/**\n * Renders `<AudioEditor>` into the element's light DOM, for\n * `createEditorElement` (sdk-core ADR 0040), as image-sdk's element does.\n * It renders without `flushSync`, since the element may connect during a\n * host's React commit; so `open()`, `insert()` and `export()` wait for the\n * first render, and the others act on the editor there is.\n */\nexport function mountAudioEditor(\n host: HTMLElement,\n initial: Partial<AudioEditorElementProps>,\n context: EditorElementContext<AudioEditorElementEvent>,\n): MountedEditor<Partial<AudioEditorElementProps>, AudioEditorElementMethods> {\n const root = createRoot(host);\n const handle: { current: AudioEditorHandle | null } = { current: null };\n let resolveReady: (editor: AudioEditorHandle) => void = () => {};\n const ready = new Promise<AudioEditorHandle>((resolve) => {\n resolveReady = resolve;\n });\n const setHandle: RefCallback<AudioEditorHandle> = (editor) => {\n handle.current = editor;\n if (editor) resolveReady(editor);\n };\n const dispatch = context.dispatch;\n\n const render = (values: Partial<AudioEditorElementProps>) => {\n // The colour mode is ui's attribute on the element itself, so changing it\n // never re-renders the editor.\n const mode = values.theme;\n if (mode && MODES.has(mode)) host.setAttribute(\"data-hm-theme\", mode);\n else host.removeAttribute(\"data-hm-theme\");\n root.render(\n <ElementEditor values={values} setHandle={setHandle} handle={handle} dispatch={dispatch} />,\n );\n };\n render(initial);\n\n const now = (): AudioEditorHandle | null => handle.current;\n return {\n update: render,\n unmount: () => {\n root.unmount();\n host.removeAttribute(\"data-hm-theme\");\n },\n handle: {\n open: async (file) => (await ready).open(file),\n insert: async (file, options) => (await ready).insert(file, options),\n export: async (options) => (await ready).export(options),\n undo: () => now()?.undo(),\n redo: () => now()?.redo(),\n play: async () => (await ready).play(),\n pause: () => now()?.pause(),\n seek: (frame) => now()?.seek(frame),\n },\n };\n}\n","/**\n * The `<hm-audio-editor>` custom element of the audio SDK.\n *\n * @remarks\n * Importing this entry registers nothing: applications call\n * `defineAudioEditorElement()` themselves, and importing it on a server does\n * nothing (sdk-core ADR 0004, ADR 0007). The element renders\n * `<AudioEditor>` into its light DOM, so React and React DOM, the package's\n * optional peer dependencies, are needed here. Hosts import\n * `@hussmartinez/ui/styles.css` once, then this package's `styles.css`\n * (sdk-core ADR 0036).\n *\n * @packageDocumentation\n */\n\nimport { createEditorElement } from \"@hussmartinez/sdk-core/element\";\nimport type { AudioExportReport } from \"./react/element/listeners.js\";\nimport {\n type AudioEditorElementEvent,\n type AudioEditorElementMethods,\n type AudioEditorElementProps,\n mountAudioEditor,\n} from \"./react/element/mount.js\";\n\nexport type {\n AudioEditorElementEvent,\n AudioEditorElementMethods,\n AudioEditorElementProps,\n AudioExportReport,\n};\n\n/** A space-separated list, as the `tools` attribute holds. */\nconst words = (value: string): readonly string[] => value.split(/\\s+/).filter(Boolean);\n\n/**\n * Registers `<hm-audio-editor>`, or the tag you name, and returns its class\n * (docs/adr/0005, sdk-core ADR 0040), as image-sdk's element does: the\n * attributes `theme`, `locale` and `tools`; the properties `file`,\n * `fileName`, `headingLevel`, `filePolicy`, `assetsUrl`, `messages`,\n * `engine`, `processor` and `output`; the methods `open`, `insert`,\n * `export`, `undo`, `redo`, `play`, `pause` and `seek`; and the events\n * `hm-audio-editor-change`, `-event`, `-export` and `-error`. Calling it\n * again returns the same class.\n *\n * @example\n * ```ts\n * import { defineAudioEditorElement } from \"@hussmartinez/audio-sdk/element\";\n *\n * defineAudioEditorElement();\n * const editor = document.querySelector(\"hm-audio-editor\");\n * editor.file = file;\n * editor.addEventListener(\"hm-audio-editor-change\", (event) => save(event.detail));\n * ```\n *\n * @public\n */\nexport const defineAudioEditorElement = /* @__PURE__ */ createEditorElement<\n Partial<AudioEditorElementProps>,\n AudioEditorElementMethods,\n AudioEditorElementEvent\n>({\n kind: \"audio\",\n attributes: {\n theme: \"theme\",\n locale: \"locale\",\n tools: { property: \"tools\", parse: words },\n },\n properties: [\n \"file\",\n \"fileName\",\n \"headingLevel\",\n \"filePolicy\",\n \"assetsUrl\",\n \"messages\",\n \"engine\",\n \"processor\",\n \"output\",\n ],\n methods: [\"open\", \"insert\", \"export\", \"undo\", \"redo\", \"play\", \"pause\", \"seek\"],\n events: [\"change\", \"event\", \"export\", \"error\"],\n mount: mountAudioEditor,\n});\n"],"mappings":";;;;;;AAmEA,IAAM,wBAAQ,IAAI,IAAI;CAAC;CAAS;CAAQ;AAAQ,CAAC;AASjD,SAAS,cAAc,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