ssml-builder-js 1.0.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/LICENSE +21 -0
- package/README.md +509 -0
- package/dist/chunk-6S5ODO6A.mjs +20 -0
- package/dist/chunk-6S5ODO6A.mjs.map +1 -0
- package/dist/chunk-I3GP7OJU.mjs +851 -0
- package/dist/chunk-I3GP7OJU.mjs.map +1 -0
- package/dist/core.d.mts +159 -0
- package/dist/core.d.ts +159 -0
- package/dist/core.js +881 -0
- package/dist/core.js.map +1 -0
- package/dist/core.mjs +14 -0
- package/dist/core.mjs.map +1 -0
- package/dist/index.d.mts +36 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.js +1054 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +177 -0
- package/dist/index.mjs.map +1 -0
- package/dist/react.d.mts +373 -0
- package/dist/react.d.ts +373 -0
- package/dist/react.js +4402 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +4364 -0
- package/dist/react.mjs.map +1 -0
- package/package.json +83 -0
package/dist/react.js
ADDED
|
@@ -0,0 +1,4402 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// src/react.tsx
|
|
32
|
+
var react_exports = {};
|
|
33
|
+
__export(react_exports, {
|
|
34
|
+
EDITOR_COPY: () => EDITOR_COPY,
|
|
35
|
+
INLINE_BADGE_COPY: () => INLINE_BADGE_COPY,
|
|
36
|
+
SSML_HOVER_COPY: () => SSML_HOVER_COPY,
|
|
37
|
+
SSML_INSERTIONS: () => SSML_INSERTIONS,
|
|
38
|
+
SsmlEditor: () => SsmlEditor,
|
|
39
|
+
createSsmlEditorInsertionDefinition: () => createSsmlEditorInsertionDefinition
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(react_exports);
|
|
42
|
+
|
|
43
|
+
// packages/ssml-editor-react/src/SsmlEditor.tsx
|
|
44
|
+
var import_react = require("react");
|
|
45
|
+
var import_react2 = __toESM(require("@monaco-editor/react"));
|
|
46
|
+
var import_react_dom = require("react-dom");
|
|
47
|
+
|
|
48
|
+
// packages/ssml-core/dist/index.mjs
|
|
49
|
+
var __typeError = (msg) => {
|
|
50
|
+
throw TypeError(msg);
|
|
51
|
+
};
|
|
52
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
53
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
54
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
55
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
56
|
+
var SYNTHESIS_NAMESPACE = "http://www.w3.org/2001/10/synthesis";
|
|
57
|
+
var MSTTS_NAMESPACE = "http://www.w3.org/2001/mstts";
|
|
58
|
+
var DEFAULT_SSML_VERSION = "1.0";
|
|
59
|
+
var DEFAULT_SSML_LANGUAGE = "en-US";
|
|
60
|
+
var MAX_NESTING_DEPTH = 1e3;
|
|
61
|
+
var XML_NAME_PATTERN = /^[A-Za-z_][A-Za-z0-9_.:-]*$/;
|
|
62
|
+
var MSTTS_TAG_PREFIX = "mstts:";
|
|
63
|
+
var SSML_TAGS = {
|
|
64
|
+
SPEAK: "speak",
|
|
65
|
+
VOICE: "voice",
|
|
66
|
+
PROSODY: "prosody",
|
|
67
|
+
BREAK: "break",
|
|
68
|
+
EXPRESS_AS: "express-as",
|
|
69
|
+
EXPRESS_AS_CAMEL: "expressAs",
|
|
70
|
+
MSTTS_EXPRESS_AS: "mstts:express-as",
|
|
71
|
+
SAY_AS: "say-as",
|
|
72
|
+
SAY_AS_CAMEL: "sayAs",
|
|
73
|
+
PHONEME: "phoneme",
|
|
74
|
+
EMPHASIS: "emphasis",
|
|
75
|
+
AUDIO: "audio",
|
|
76
|
+
SUB: "sub",
|
|
77
|
+
LANG: "lang",
|
|
78
|
+
MARK: "mark",
|
|
79
|
+
BOOKMARK: "bookmark",
|
|
80
|
+
LEXICON: "lexicon",
|
|
81
|
+
PARAGRAPH: "p",
|
|
82
|
+
SENTENCE: "s",
|
|
83
|
+
WORD: "w",
|
|
84
|
+
MSTTS_SILENCE: "mstts:silence",
|
|
85
|
+
SILENCE: "silence",
|
|
86
|
+
MSTTS_VISEME: "mstts:viseme",
|
|
87
|
+
VISEME: "viseme"
|
|
88
|
+
};
|
|
89
|
+
var SSML_ATTRS = {
|
|
90
|
+
VERSION: "version",
|
|
91
|
+
XMLNS: "xmlns",
|
|
92
|
+
XML_LANG: "xml:lang",
|
|
93
|
+
LANG: "lang",
|
|
94
|
+
MSTTS_XMLNS: "xmlns:mstts",
|
|
95
|
+
NAME: "name",
|
|
96
|
+
EFFECT: "effect",
|
|
97
|
+
RATE: "rate",
|
|
98
|
+
PITCH: "pitch",
|
|
99
|
+
VOLUME: "volume",
|
|
100
|
+
CONTOUR: "contour",
|
|
101
|
+
RANGE: "range",
|
|
102
|
+
TIME: "time",
|
|
103
|
+
STRENGTH: "strength",
|
|
104
|
+
STYLE: "style",
|
|
105
|
+
STYLE_DEGREE: "styledegree",
|
|
106
|
+
STYLE_DEGREE_CAMEL: "styleDegree",
|
|
107
|
+
ROLE: "role",
|
|
108
|
+
INTERPRET_AS: "interpret-as",
|
|
109
|
+
FORMAT: "format",
|
|
110
|
+
DETAIL: "detail",
|
|
111
|
+
ALPHABET: "alphabet",
|
|
112
|
+
PH: "ph",
|
|
113
|
+
LEVEL: "level",
|
|
114
|
+
SRC: "src",
|
|
115
|
+
DESC: "desc",
|
|
116
|
+
CLIP_BEGIN: "clipBegin",
|
|
117
|
+
CLIP_END: "clipEnd",
|
|
118
|
+
SPEED: "speed",
|
|
119
|
+
REPEAT_COUNT: "repeatCount",
|
|
120
|
+
REPEAT_DURATION: "repeatDuration",
|
|
121
|
+
SOUND_LEVEL: "soundLevel",
|
|
122
|
+
ALIAS: "alias",
|
|
123
|
+
MARK: "mark",
|
|
124
|
+
URI: "uri",
|
|
125
|
+
TYPE: "type",
|
|
126
|
+
VALUE: "value"
|
|
127
|
+
};
|
|
128
|
+
function escapeText(value) {
|
|
129
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
130
|
+
}
|
|
131
|
+
function escapeAttribute(value) {
|
|
132
|
+
return escapeText(value).replace(/"/g, """).replace(/'/g, "'");
|
|
133
|
+
}
|
|
134
|
+
function addAttribute(attributes, name, value) {
|
|
135
|
+
if (value !== void 0) {
|
|
136
|
+
attributes[name] = value;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
function getAttributes(element) {
|
|
140
|
+
const attributes = {
|
|
141
|
+
...element.attributes ?? {}
|
|
142
|
+
};
|
|
143
|
+
switch (element.type) {
|
|
144
|
+
case SSML_TAGS.VOICE:
|
|
145
|
+
addAttribute(attributes, SSML_ATTRS.NAME, element.name);
|
|
146
|
+
addAttribute(attributes, SSML_ATTRS.EFFECT, element.effect);
|
|
147
|
+
break;
|
|
148
|
+
case SSML_TAGS.PROSODY:
|
|
149
|
+
addAttribute(attributes, SSML_ATTRS.RATE, element.rate);
|
|
150
|
+
addAttribute(attributes, SSML_ATTRS.PITCH, element.pitch);
|
|
151
|
+
addAttribute(attributes, SSML_ATTRS.VOLUME, element.volume);
|
|
152
|
+
addAttribute(attributes, SSML_ATTRS.CONTOUR, element.contour);
|
|
153
|
+
addAttribute(attributes, SSML_ATTRS.RANGE, element.range);
|
|
154
|
+
break;
|
|
155
|
+
case SSML_TAGS.BREAK:
|
|
156
|
+
addAttribute(attributes, SSML_ATTRS.TIME, element.time);
|
|
157
|
+
addAttribute(attributes, SSML_ATTRS.STRENGTH, element.strength);
|
|
158
|
+
break;
|
|
159
|
+
case SSML_TAGS.EXPRESS_AS:
|
|
160
|
+
case SSML_TAGS.EXPRESS_AS_CAMEL:
|
|
161
|
+
case SSML_TAGS.MSTTS_EXPRESS_AS:
|
|
162
|
+
addAttribute(attributes, SSML_ATTRS.STYLE, element.style);
|
|
163
|
+
addAttribute(attributes, SSML_ATTRS.STYLE_DEGREE, element.styleDegree);
|
|
164
|
+
addAttribute(attributes, SSML_ATTRS.ROLE, element.role);
|
|
165
|
+
break;
|
|
166
|
+
case SSML_TAGS.SAY_AS:
|
|
167
|
+
case SSML_TAGS.SAY_AS_CAMEL:
|
|
168
|
+
addAttribute(attributes, SSML_ATTRS.INTERPRET_AS, element.interpretAs);
|
|
169
|
+
addAttribute(attributes, SSML_ATTRS.FORMAT, element.format);
|
|
170
|
+
addAttribute(attributes, SSML_ATTRS.DETAIL, element.detail);
|
|
171
|
+
break;
|
|
172
|
+
case SSML_TAGS.PHONEME:
|
|
173
|
+
addAttribute(attributes, SSML_ATTRS.ALPHABET, element.alphabet);
|
|
174
|
+
addAttribute(attributes, SSML_ATTRS.PH, element.ph);
|
|
175
|
+
break;
|
|
176
|
+
case SSML_TAGS.EMPHASIS:
|
|
177
|
+
addAttribute(attributes, SSML_ATTRS.LEVEL, element.level);
|
|
178
|
+
break;
|
|
179
|
+
case SSML_TAGS.AUDIO:
|
|
180
|
+
addAttribute(attributes, SSML_ATTRS.SRC, element.src);
|
|
181
|
+
addAttribute(attributes, SSML_ATTRS.DESC, element.desc);
|
|
182
|
+
addAttribute(attributes, SSML_ATTRS.CLIP_BEGIN, element.clipBegin);
|
|
183
|
+
addAttribute(attributes, SSML_ATTRS.CLIP_END, element.clipEnd);
|
|
184
|
+
addAttribute(attributes, SSML_ATTRS.SPEED, element.speed);
|
|
185
|
+
addAttribute(attributes, SSML_ATTRS.REPEAT_COUNT, element.repeatCount);
|
|
186
|
+
addAttribute(attributes, SSML_ATTRS.REPEAT_DURATION, element.repeatDuration);
|
|
187
|
+
addAttribute(attributes, SSML_ATTRS.SOUND_LEVEL, element.soundLevel);
|
|
188
|
+
break;
|
|
189
|
+
case SSML_TAGS.SUB:
|
|
190
|
+
addAttribute(attributes, SSML_ATTRS.ALIAS, element.alias);
|
|
191
|
+
break;
|
|
192
|
+
case SSML_TAGS.LANG:
|
|
193
|
+
addAttribute(attributes, SSML_ATTRS.XML_LANG, element.lang);
|
|
194
|
+
break;
|
|
195
|
+
case SSML_TAGS.MARK:
|
|
196
|
+
addAttribute(attributes, SSML_ATTRS.NAME, element.name);
|
|
197
|
+
break;
|
|
198
|
+
case SSML_TAGS.BOOKMARK:
|
|
199
|
+
addAttribute(attributes, SSML_ATTRS.MARK, element.mark);
|
|
200
|
+
break;
|
|
201
|
+
case SSML_TAGS.LEXICON:
|
|
202
|
+
addAttribute(attributes, SSML_ATTRS.URI, element.uri);
|
|
203
|
+
break;
|
|
204
|
+
case SSML_TAGS.MSTTS_SILENCE:
|
|
205
|
+
case SSML_TAGS.SILENCE:
|
|
206
|
+
addAttribute(attributes, SSML_ATTRS.TYPE, element.typeValue ?? element.silenceType);
|
|
207
|
+
addAttribute(attributes, SSML_ATTRS.VALUE, element.value);
|
|
208
|
+
break;
|
|
209
|
+
case SSML_TAGS.MSTTS_VISEME:
|
|
210
|
+
case SSML_TAGS.VISEME:
|
|
211
|
+
addAttribute(attributes, SSML_ATTRS.TYPE, element.typeValue ?? element.visemeType);
|
|
212
|
+
break;
|
|
213
|
+
case SSML_TAGS.PARAGRAPH:
|
|
214
|
+
case SSML_TAGS.SENTENCE:
|
|
215
|
+
case SSML_TAGS.WORD:
|
|
216
|
+
case "element":
|
|
217
|
+
case "custom":
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
return attributes;
|
|
221
|
+
}
|
|
222
|
+
function getTagName(element) {
|
|
223
|
+
switch (element.type) {
|
|
224
|
+
case SSML_TAGS.EXPRESS_AS:
|
|
225
|
+
case SSML_TAGS.EXPRESS_AS_CAMEL:
|
|
226
|
+
case SSML_TAGS.MSTTS_EXPRESS_AS:
|
|
227
|
+
return SSML_TAGS.MSTTS_EXPRESS_AS;
|
|
228
|
+
case SSML_TAGS.SAY_AS:
|
|
229
|
+
case SSML_TAGS.SAY_AS_CAMEL:
|
|
230
|
+
return SSML_TAGS.SAY_AS;
|
|
231
|
+
case SSML_TAGS.SILENCE:
|
|
232
|
+
case SSML_TAGS.MSTTS_SILENCE:
|
|
233
|
+
return SSML_TAGS.MSTTS_SILENCE;
|
|
234
|
+
case SSML_TAGS.VISEME:
|
|
235
|
+
case SSML_TAGS.MSTTS_VISEME:
|
|
236
|
+
return SSML_TAGS.MSTTS_VISEME;
|
|
237
|
+
case "element":
|
|
238
|
+
case "custom":
|
|
239
|
+
return element.name;
|
|
240
|
+
default:
|
|
241
|
+
return element.type;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
function getChildren(element) {
|
|
245
|
+
return element.children ?? [];
|
|
246
|
+
}
|
|
247
|
+
function validateName(name, kind) {
|
|
248
|
+
if (!XML_NAME_PATTERN.test(name)) {
|
|
249
|
+
throw new Error(`Invalid XML ${kind} name: ${name}`);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
function serializeAttributes(attributes) {
|
|
253
|
+
return Object.entries(attributes).map(([name, value]) => {
|
|
254
|
+
validateName(name, "attribute");
|
|
255
|
+
return ` ${name}="${escapeAttribute(String(value))}"`;
|
|
256
|
+
}).join("");
|
|
257
|
+
}
|
|
258
|
+
function serializeNode(node) {
|
|
259
|
+
if (typeof node === "string") {
|
|
260
|
+
return escapeText(node);
|
|
261
|
+
}
|
|
262
|
+
if (node.type === "text") {
|
|
263
|
+
return escapeText(node.value);
|
|
264
|
+
}
|
|
265
|
+
const tagName = getTagName(node);
|
|
266
|
+
validateName(tagName, "element");
|
|
267
|
+
const attributes = serializeAttributes(getAttributes(node));
|
|
268
|
+
const children = getChildren(node);
|
|
269
|
+
if (children.length === 0) {
|
|
270
|
+
return `<${tagName}${attributes}/>`;
|
|
271
|
+
}
|
|
272
|
+
return `<${tagName}${attributes}>${children.map(serializeNode).join("")}</${tagName}>`;
|
|
273
|
+
}
|
|
274
|
+
function usesMsttsNamespace(nodes) {
|
|
275
|
+
return nodes.some((node) => {
|
|
276
|
+
if (typeof node === "string" || node.type === "text") {
|
|
277
|
+
return false;
|
|
278
|
+
}
|
|
279
|
+
const tagName = getTagName(node);
|
|
280
|
+
return tagName.startsWith(MSTTS_TAG_PREFIX) || usesMsttsNamespace(getChildren(node));
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
function serializeDocument(document2) {
|
|
284
|
+
const children = document2.children ?? (document2.content === void 0 ? [] : [document2.content]);
|
|
285
|
+
const attributes = {
|
|
286
|
+
...document2.attributes ?? {},
|
|
287
|
+
[SSML_ATTRS.VERSION]: document2.version,
|
|
288
|
+
[SSML_ATTRS.XMLNS]: SYNTHESIS_NAMESPACE,
|
|
289
|
+
[SSML_ATTRS.XML_LANG]: document2.lang
|
|
290
|
+
};
|
|
291
|
+
if (usesMsttsNamespace(children) && attributes[SSML_ATTRS.MSTTS_XMLNS] === void 0) {
|
|
292
|
+
attributes[SSML_ATTRS.MSTTS_XMLNS] = MSTTS_NAMESPACE;
|
|
293
|
+
}
|
|
294
|
+
return `<${SSML_TAGS.SPEAK}${serializeAttributes(attributes)}>${children.map(serializeNode).join("")}</${SSML_TAGS.SPEAK}>`;
|
|
295
|
+
}
|
|
296
|
+
function buildSsml(documentOrContent, lang = DEFAULT_SSML_LANGUAGE) {
|
|
297
|
+
if (typeof documentOrContent === "string") {
|
|
298
|
+
return {
|
|
299
|
+
version: DEFAULT_SSML_VERSION,
|
|
300
|
+
lang,
|
|
301
|
+
content: documentOrContent
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
return serializeDocument(documentOrContent);
|
|
305
|
+
}
|
|
306
|
+
var XML_ENTITIES = {
|
|
307
|
+
amp: "&",
|
|
308
|
+
apos: "'",
|
|
309
|
+
gt: ">",
|
|
310
|
+
lt: "<",
|
|
311
|
+
quot: '"'
|
|
312
|
+
};
|
|
313
|
+
function hasOwn(object, property) {
|
|
314
|
+
return Object.getOwnPropertyDescriptor(object, property) !== void 0;
|
|
315
|
+
}
|
|
316
|
+
function setAttribute(attributes, name, value) {
|
|
317
|
+
Object.defineProperty(attributes, name, {
|
|
318
|
+
configurable: true,
|
|
319
|
+
enumerable: true,
|
|
320
|
+
value,
|
|
321
|
+
writable: true
|
|
322
|
+
});
|
|
323
|
+
}
|
|
324
|
+
function decodeEntity(entity) {
|
|
325
|
+
const namedValue = hasOwn(XML_ENTITIES, entity) ? XML_ENTITIES[entity] : void 0;
|
|
326
|
+
if (namedValue !== void 0) {
|
|
327
|
+
return namedValue;
|
|
328
|
+
}
|
|
329
|
+
const isHexadecimal = entity.startsWith("#x") || entity.startsWith("#X");
|
|
330
|
+
const isDecimal = entity.startsWith("#");
|
|
331
|
+
if (!isHexadecimal && !isDecimal) {
|
|
332
|
+
throw new Error(`Unknown XML entity: &${entity};`);
|
|
333
|
+
}
|
|
334
|
+
const digits = entity.slice(isHexadecimal ? 2 : 1);
|
|
335
|
+
const codePoint = Number.parseInt(digits, isHexadecimal ? 16 : 10);
|
|
336
|
+
if (!digits || !Number.isInteger(codePoint) || codePoint < 0 || codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343 || codePoint < 32 && ![9, 10, 13].includes(codePoint)) {
|
|
337
|
+
throw new Error(`Invalid XML character reference: &${entity};`);
|
|
338
|
+
}
|
|
339
|
+
return String.fromCodePoint(codePoint);
|
|
340
|
+
}
|
|
341
|
+
function decodeXmlEntities(value) {
|
|
342
|
+
let result = "";
|
|
343
|
+
let start = 0;
|
|
344
|
+
while (true) {
|
|
345
|
+
const ampersand = value.indexOf("&", start);
|
|
346
|
+
if (ampersand === -1) {
|
|
347
|
+
return result + value.slice(start);
|
|
348
|
+
}
|
|
349
|
+
result += value.slice(start, ampersand);
|
|
350
|
+
const semicolon = value.indexOf(";", ampersand + 1);
|
|
351
|
+
if (semicolon === -1) {
|
|
352
|
+
throw new Error("Unterminated XML entity reference");
|
|
353
|
+
}
|
|
354
|
+
result += decodeEntity(value.slice(ampersand + 1, semicolon));
|
|
355
|
+
start = semicolon + 1;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
function isXmlNameStart(value) {
|
|
359
|
+
return value !== void 0 && /[A-Za-z_]/.test(value);
|
|
360
|
+
}
|
|
361
|
+
function isXmlNameCharacter(value) {
|
|
362
|
+
return value !== void 0 && /[A-Za-z0-9_.:-]/.test(value);
|
|
363
|
+
}
|
|
364
|
+
function isXmlWhitespace(value) {
|
|
365
|
+
return value === " " || value === " " || value === "\r" || value === "\n";
|
|
366
|
+
}
|
|
367
|
+
function removeStandardNamespaceAttributes(attributes) {
|
|
368
|
+
if (attributes[SSML_ATTRS.XMLNS] === SYNTHESIS_NAMESPACE) {
|
|
369
|
+
delete attributes[SSML_ATTRS.XMLNS];
|
|
370
|
+
}
|
|
371
|
+
if (attributes[SSML_ATTRS.MSTTS_XMLNS] === MSTTS_NAMESPACE) {
|
|
372
|
+
delete attributes[SSML_ATTRS.MSTTS_XMLNS];
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
var _index;
|
|
376
|
+
var XmlParser = class {
|
|
377
|
+
constructor(source) {
|
|
378
|
+
__privateAdd(this, _index, 0);
|
|
379
|
+
this.source = source;
|
|
380
|
+
}
|
|
381
|
+
parse() {
|
|
382
|
+
if (this.source.charCodeAt(0) === 65279) {
|
|
383
|
+
__privateSet(this, _index, __privateGet(this, _index) + 1);
|
|
384
|
+
}
|
|
385
|
+
this.skipMisc();
|
|
386
|
+
if (__privateGet(this, _index) >= this.source.length) {
|
|
387
|
+
this.fail("SSML input is empty");
|
|
388
|
+
}
|
|
389
|
+
if (this.source[__privateGet(this, _index)] !== "<") {
|
|
390
|
+
this.fail("SSML input must start with an XML element");
|
|
391
|
+
}
|
|
392
|
+
const root = this.parseElement(0);
|
|
393
|
+
this.skipMisc();
|
|
394
|
+
if (__privateGet(this, _index) !== this.source.length) {
|
|
395
|
+
this.fail("Unexpected content after the root XML element");
|
|
396
|
+
}
|
|
397
|
+
return root;
|
|
398
|
+
}
|
|
399
|
+
parseElement(depth) {
|
|
400
|
+
if (depth > MAX_NESTING_DEPTH) {
|
|
401
|
+
this.fail("XML nesting depth exceeds the supported limit");
|
|
402
|
+
}
|
|
403
|
+
this.expect("<");
|
|
404
|
+
if (this.source[__privateGet(this, _index)] === "/") {
|
|
405
|
+
this.fail("Unexpected closing XML element");
|
|
406
|
+
}
|
|
407
|
+
const name = this.parseName();
|
|
408
|
+
const { attributes, selfClosing } = this.parseStartTag();
|
|
409
|
+
if (selfClosing) {
|
|
410
|
+
return { name, attributes, children: [] };
|
|
411
|
+
}
|
|
412
|
+
const children = [];
|
|
413
|
+
while (__privateGet(this, _index) < this.source.length) {
|
|
414
|
+
if (this.source.startsWith("</", __privateGet(this, _index))) {
|
|
415
|
+
__privateSet(this, _index, __privateGet(this, _index) + 2);
|
|
416
|
+
const closingName = this.parseName();
|
|
417
|
+
this.skipWhitespace();
|
|
418
|
+
this.expect(">");
|
|
419
|
+
if (closingName !== name) {
|
|
420
|
+
this.fail(`Mismatched closing element: expected </${name}> but found </${closingName}>`);
|
|
421
|
+
}
|
|
422
|
+
return { name, attributes, children };
|
|
423
|
+
}
|
|
424
|
+
if (this.source.startsWith("<!--", __privateGet(this, _index))) {
|
|
425
|
+
this.skipComment();
|
|
426
|
+
continue;
|
|
427
|
+
}
|
|
428
|
+
if (this.source.startsWith("<![CDATA[", __privateGet(this, _index))) {
|
|
429
|
+
this.appendText(children, this.parseCdata());
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
432
|
+
if (this.source.startsWith("<?", __privateGet(this, _index))) {
|
|
433
|
+
this.skipProcessingInstruction();
|
|
434
|
+
continue;
|
|
435
|
+
}
|
|
436
|
+
if (this.source.startsWith("<!", __privateGet(this, _index))) {
|
|
437
|
+
this.fail("Unsupported XML declaration inside an element");
|
|
438
|
+
}
|
|
439
|
+
if (this.source[__privateGet(this, _index)] === "<") {
|
|
440
|
+
children.push(this.parseElement(depth + 1));
|
|
441
|
+
} else {
|
|
442
|
+
this.appendText(children, this.parseText());
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
this.fail(`Unclosed XML element: <${name}>`);
|
|
446
|
+
}
|
|
447
|
+
parseStartTag() {
|
|
448
|
+
const attributes = {};
|
|
449
|
+
while (__privateGet(this, _index) < this.source.length) {
|
|
450
|
+
this.skipWhitespace();
|
|
451
|
+
if (this.source.startsWith("/>", __privateGet(this, _index))) {
|
|
452
|
+
__privateSet(this, _index, __privateGet(this, _index) + 2);
|
|
453
|
+
return { attributes, selfClosing: true };
|
|
454
|
+
}
|
|
455
|
+
if (this.source[__privateGet(this, _index)] === ">") {
|
|
456
|
+
__privateSet(this, _index, __privateGet(this, _index) + 1);
|
|
457
|
+
return { attributes, selfClosing: false };
|
|
458
|
+
}
|
|
459
|
+
const name = this.parseName();
|
|
460
|
+
this.skipWhitespace();
|
|
461
|
+
this.expect("=");
|
|
462
|
+
this.skipWhitespace();
|
|
463
|
+
const quote = this.source[__privateGet(this, _index)];
|
|
464
|
+
if (quote !== '"' && quote !== "'") {
|
|
465
|
+
this.fail(`XML attribute ${name} must use a quoted value`);
|
|
466
|
+
}
|
|
467
|
+
__privateSet(this, _index, __privateGet(this, _index) + 1);
|
|
468
|
+
const valueStart = __privateGet(this, _index);
|
|
469
|
+
while (__privateGet(this, _index) < this.source.length && this.source[__privateGet(this, _index)] !== quote) {
|
|
470
|
+
if (this.source[__privateGet(this, _index)] === "<") {
|
|
471
|
+
this.fail(`Invalid "<" in XML attribute ${name}`);
|
|
472
|
+
}
|
|
473
|
+
__privateSet(this, _index, __privateGet(this, _index) + 1);
|
|
474
|
+
}
|
|
475
|
+
if (__privateGet(this, _index) >= this.source.length) {
|
|
476
|
+
this.fail(`Unclosed XML attribute ${name}`);
|
|
477
|
+
}
|
|
478
|
+
const value = decodeXmlEntities(this.source.slice(valueStart, __privateGet(this, _index)));
|
|
479
|
+
__privateSet(this, _index, __privateGet(this, _index) + 1);
|
|
480
|
+
if (hasOwn(attributes, name)) {
|
|
481
|
+
this.fail(`Duplicate XML attribute: ${name}`);
|
|
482
|
+
}
|
|
483
|
+
setAttribute(attributes, name, value);
|
|
484
|
+
}
|
|
485
|
+
this.fail("Unclosed XML start tag");
|
|
486
|
+
}
|
|
487
|
+
parseText() {
|
|
488
|
+
const start = __privateGet(this, _index);
|
|
489
|
+
while (__privateGet(this, _index) < this.source.length && this.source[__privateGet(this, _index)] !== "<") {
|
|
490
|
+
__privateSet(this, _index, __privateGet(this, _index) + 1);
|
|
491
|
+
}
|
|
492
|
+
const value = this.source.slice(start, __privateGet(this, _index));
|
|
493
|
+
if (value.includes("]]>")) {
|
|
494
|
+
this.fail("CDATA termination is not valid in ordinary XML text");
|
|
495
|
+
}
|
|
496
|
+
return decodeXmlEntities(value);
|
|
497
|
+
}
|
|
498
|
+
parseCdata() {
|
|
499
|
+
__privateSet(this, _index, __privateGet(this, _index) + "<![CDATA[".length);
|
|
500
|
+
const end = this.source.indexOf("]]>", __privateGet(this, _index));
|
|
501
|
+
if (end === -1) {
|
|
502
|
+
this.fail("Unclosed XML CDATA section");
|
|
503
|
+
}
|
|
504
|
+
const value = this.source.slice(__privateGet(this, _index), end);
|
|
505
|
+
__privateSet(this, _index, end + 3);
|
|
506
|
+
return value;
|
|
507
|
+
}
|
|
508
|
+
skipComment() {
|
|
509
|
+
__privateSet(this, _index, __privateGet(this, _index) + "<!--".length);
|
|
510
|
+
const end = this.source.indexOf("-->", __privateGet(this, _index));
|
|
511
|
+
if (end === -1) {
|
|
512
|
+
this.fail("Unclosed XML comment");
|
|
513
|
+
}
|
|
514
|
+
if (this.source.slice(__privateGet(this, _index), end).includes("--")) {
|
|
515
|
+
this.fail("XML comments cannot contain consecutive hyphens");
|
|
516
|
+
}
|
|
517
|
+
__privateSet(this, _index, end + 3);
|
|
518
|
+
}
|
|
519
|
+
skipProcessingInstruction() {
|
|
520
|
+
__privateSet(this, _index, __privateGet(this, _index) + "<?".length);
|
|
521
|
+
this.parseName();
|
|
522
|
+
const end = this.source.indexOf("?>", __privateGet(this, _index));
|
|
523
|
+
if (end === -1) {
|
|
524
|
+
this.fail("Unclosed XML processing instruction");
|
|
525
|
+
}
|
|
526
|
+
__privateSet(this, _index, end + 2);
|
|
527
|
+
}
|
|
528
|
+
skipMisc() {
|
|
529
|
+
while (__privateGet(this, _index) < this.source.length) {
|
|
530
|
+
this.skipWhitespace();
|
|
531
|
+
if (this.source.startsWith("<!--", __privateGet(this, _index))) {
|
|
532
|
+
this.skipComment();
|
|
533
|
+
continue;
|
|
534
|
+
}
|
|
535
|
+
if (this.source.startsWith("<?", __privateGet(this, _index))) {
|
|
536
|
+
this.skipProcessingInstruction();
|
|
537
|
+
continue;
|
|
538
|
+
}
|
|
539
|
+
if (this.source.startsWith("<!DOCTYPE", __privateGet(this, _index))) {
|
|
540
|
+
this.fail("DOCTYPE declarations are not supported");
|
|
541
|
+
}
|
|
542
|
+
break;
|
|
543
|
+
}
|
|
544
|
+
}
|
|
545
|
+
parseName() {
|
|
546
|
+
const first = this.source[__privateGet(this, _index)];
|
|
547
|
+
if (!isXmlNameStart(first)) {
|
|
548
|
+
this.fail("Invalid XML name");
|
|
549
|
+
}
|
|
550
|
+
const start = __privateGet(this, _index);
|
|
551
|
+
__privateSet(this, _index, __privateGet(this, _index) + 1);
|
|
552
|
+
while (isXmlNameCharacter(this.source[__privateGet(this, _index)])) {
|
|
553
|
+
__privateSet(this, _index, __privateGet(this, _index) + 1);
|
|
554
|
+
}
|
|
555
|
+
return this.source.slice(start, __privateGet(this, _index));
|
|
556
|
+
}
|
|
557
|
+
appendText(children, value) {
|
|
558
|
+
if (!value) {
|
|
559
|
+
return;
|
|
560
|
+
}
|
|
561
|
+
const previous = children[children.length - 1];
|
|
562
|
+
if (typeof previous === "string") {
|
|
563
|
+
children[children.length - 1] = previous + value;
|
|
564
|
+
} else {
|
|
565
|
+
children.push(value);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
skipWhitespace() {
|
|
569
|
+
while (isXmlWhitespace(this.source[__privateGet(this, _index)])) {
|
|
570
|
+
__privateSet(this, _index, __privateGet(this, _index) + 1);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
expect(value) {
|
|
574
|
+
if (!this.source.startsWith(value, __privateGet(this, _index))) {
|
|
575
|
+
this.fail(`Expected "${value}"`);
|
|
576
|
+
}
|
|
577
|
+
__privateSet(this, _index, __privateGet(this, _index) + value.length);
|
|
578
|
+
}
|
|
579
|
+
fail(message) {
|
|
580
|
+
throw new Error(`${message} at position ${__privateGet(this, _index)}`);
|
|
581
|
+
}
|
|
582
|
+
};
|
|
583
|
+
_index = /* @__PURE__ */ new WeakMap();
|
|
584
|
+
function readAttribute(attributes, ...names) {
|
|
585
|
+
let found = false;
|
|
586
|
+
let value;
|
|
587
|
+
for (const name of names) {
|
|
588
|
+
if (hasOwn(attributes, name)) {
|
|
589
|
+
if (!found) {
|
|
590
|
+
value = String(attributes[name]);
|
|
591
|
+
found = true;
|
|
592
|
+
}
|
|
593
|
+
delete attributes[name];
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
return value;
|
|
597
|
+
}
|
|
598
|
+
function getElementAttributes(node) {
|
|
599
|
+
const attributes = { ...node.attributes };
|
|
600
|
+
removeStandardNamespaceAttributes(attributes);
|
|
601
|
+
return attributes;
|
|
602
|
+
}
|
|
603
|
+
function finishElement(element, node, attributes) {
|
|
604
|
+
if (node.children.length > 0) {
|
|
605
|
+
element.children = node.children.map(convertNode);
|
|
606
|
+
}
|
|
607
|
+
if (Object.keys(attributes).length > 0) {
|
|
608
|
+
element.attributes = attributes;
|
|
609
|
+
}
|
|
610
|
+
return element;
|
|
611
|
+
}
|
|
612
|
+
function convertElement(node) {
|
|
613
|
+
const attributes = getElementAttributes(node);
|
|
614
|
+
switch (node.name) {
|
|
615
|
+
case SSML_TAGS.VOICE: {
|
|
616
|
+
const element = { type: SSML_TAGS.VOICE };
|
|
617
|
+
const name = readAttribute(attributes, SSML_ATTRS.NAME);
|
|
618
|
+
const effect = readAttribute(attributes, SSML_ATTRS.EFFECT);
|
|
619
|
+
if (name !== void 0) element.name = name;
|
|
620
|
+
if (effect !== void 0) element.effect = effect;
|
|
621
|
+
return finishElement(element, node, attributes);
|
|
622
|
+
}
|
|
623
|
+
case SSML_TAGS.PROSODY: {
|
|
624
|
+
const element = { type: SSML_TAGS.PROSODY };
|
|
625
|
+
const rate = readAttribute(attributes, SSML_ATTRS.RATE);
|
|
626
|
+
const pitch = readAttribute(attributes, SSML_ATTRS.PITCH);
|
|
627
|
+
const volume = readAttribute(attributes, SSML_ATTRS.VOLUME);
|
|
628
|
+
const contour = readAttribute(attributes, SSML_ATTRS.CONTOUR);
|
|
629
|
+
const range = readAttribute(attributes, SSML_ATTRS.RANGE);
|
|
630
|
+
if (rate !== void 0) element.rate = rate;
|
|
631
|
+
if (pitch !== void 0) element.pitch = pitch;
|
|
632
|
+
if (volume !== void 0) element.volume = volume;
|
|
633
|
+
if (contour !== void 0) element.contour = contour;
|
|
634
|
+
if (range !== void 0) element.range = range;
|
|
635
|
+
return finishElement(element, node, attributes);
|
|
636
|
+
}
|
|
637
|
+
case SSML_TAGS.BREAK: {
|
|
638
|
+
const element = { type: SSML_TAGS.BREAK };
|
|
639
|
+
const time = readAttribute(attributes, SSML_ATTRS.TIME);
|
|
640
|
+
const strength = readAttribute(attributes, SSML_ATTRS.STRENGTH);
|
|
641
|
+
if (time !== void 0) element.time = time;
|
|
642
|
+
if (strength !== void 0) element.strength = strength;
|
|
643
|
+
return finishElement(element, node, attributes);
|
|
644
|
+
}
|
|
645
|
+
case SSML_TAGS.EXPRESS_AS:
|
|
646
|
+
case SSML_TAGS.EXPRESS_AS_CAMEL:
|
|
647
|
+
case SSML_TAGS.MSTTS_EXPRESS_AS: {
|
|
648
|
+
const element = { type: node.name };
|
|
649
|
+
const style = readAttribute(attributes, SSML_ATTRS.STYLE);
|
|
650
|
+
const styleDegree = readAttribute(attributes, SSML_ATTRS.STYLE_DEGREE, SSML_ATTRS.STYLE_DEGREE_CAMEL);
|
|
651
|
+
const role = readAttribute(attributes, SSML_ATTRS.ROLE);
|
|
652
|
+
if (style !== void 0) element.style = style;
|
|
653
|
+
if (styleDegree !== void 0) element.styleDegree = styleDegree;
|
|
654
|
+
if (role !== void 0) element.role = role;
|
|
655
|
+
return finishElement(element, node, attributes);
|
|
656
|
+
}
|
|
657
|
+
case SSML_TAGS.SAY_AS:
|
|
658
|
+
case SSML_TAGS.SAY_AS_CAMEL: {
|
|
659
|
+
const element = { type: node.name };
|
|
660
|
+
const interpretAs = readAttribute(attributes, SSML_ATTRS.INTERPRET_AS);
|
|
661
|
+
const format = readAttribute(attributes, SSML_ATTRS.FORMAT);
|
|
662
|
+
const detail = readAttribute(attributes, SSML_ATTRS.DETAIL);
|
|
663
|
+
if (interpretAs !== void 0) element.interpretAs = interpretAs;
|
|
664
|
+
if (format !== void 0) element.format = format;
|
|
665
|
+
if (detail !== void 0) element.detail = detail;
|
|
666
|
+
return finishElement(element, node, attributes);
|
|
667
|
+
}
|
|
668
|
+
case SSML_TAGS.PHONEME: {
|
|
669
|
+
const element = { type: SSML_TAGS.PHONEME };
|
|
670
|
+
const alphabet = readAttribute(attributes, SSML_ATTRS.ALPHABET);
|
|
671
|
+
const ph = readAttribute(attributes, SSML_ATTRS.PH);
|
|
672
|
+
if (alphabet !== void 0) element.alphabet = alphabet;
|
|
673
|
+
if (ph !== void 0) element.ph = ph;
|
|
674
|
+
return finishElement(element, node, attributes);
|
|
675
|
+
}
|
|
676
|
+
case SSML_TAGS.EMPHASIS: {
|
|
677
|
+
const element = { type: SSML_TAGS.EMPHASIS };
|
|
678
|
+
const level = readAttribute(attributes, SSML_ATTRS.LEVEL);
|
|
679
|
+
if (level !== void 0) element.level = level;
|
|
680
|
+
return finishElement(element, node, attributes);
|
|
681
|
+
}
|
|
682
|
+
case SSML_TAGS.AUDIO: {
|
|
683
|
+
const element = { type: SSML_TAGS.AUDIO };
|
|
684
|
+
const src = readAttribute(attributes, SSML_ATTRS.SRC);
|
|
685
|
+
const desc = readAttribute(attributes, SSML_ATTRS.DESC);
|
|
686
|
+
const clipBegin = readAttribute(attributes, SSML_ATTRS.CLIP_BEGIN);
|
|
687
|
+
const clipEnd = readAttribute(attributes, SSML_ATTRS.CLIP_END);
|
|
688
|
+
const speed = readAttribute(attributes, SSML_ATTRS.SPEED);
|
|
689
|
+
const repeatCount = readAttribute(attributes, SSML_ATTRS.REPEAT_COUNT);
|
|
690
|
+
const repeatDuration = readAttribute(attributes, SSML_ATTRS.REPEAT_DURATION);
|
|
691
|
+
const soundLevel = readAttribute(attributes, SSML_ATTRS.SOUND_LEVEL);
|
|
692
|
+
if (src !== void 0) element.src = src;
|
|
693
|
+
if (desc !== void 0) element.desc = desc;
|
|
694
|
+
if (clipBegin !== void 0) element.clipBegin = clipBegin;
|
|
695
|
+
if (clipEnd !== void 0) element.clipEnd = clipEnd;
|
|
696
|
+
if (speed !== void 0) element.speed = speed;
|
|
697
|
+
if (repeatCount !== void 0) element.repeatCount = repeatCount;
|
|
698
|
+
if (repeatDuration !== void 0) element.repeatDuration = repeatDuration;
|
|
699
|
+
if (soundLevel !== void 0) element.soundLevel = soundLevel;
|
|
700
|
+
return finishElement(element, node, attributes);
|
|
701
|
+
}
|
|
702
|
+
case SSML_TAGS.SUB: {
|
|
703
|
+
const element = { type: SSML_TAGS.SUB };
|
|
704
|
+
const alias = readAttribute(attributes, SSML_ATTRS.ALIAS);
|
|
705
|
+
if (alias !== void 0) element.alias = alias;
|
|
706
|
+
return finishElement(element, node, attributes);
|
|
707
|
+
}
|
|
708
|
+
case SSML_TAGS.LANG: {
|
|
709
|
+
const element = { type: SSML_TAGS.LANG };
|
|
710
|
+
const lang = readAttribute(attributes, SSML_ATTRS.XML_LANG, SSML_ATTRS.LANG);
|
|
711
|
+
if (lang !== void 0) element.lang = lang;
|
|
712
|
+
return finishElement(element, node, attributes);
|
|
713
|
+
}
|
|
714
|
+
case SSML_TAGS.MARK: {
|
|
715
|
+
const element = { type: SSML_TAGS.MARK };
|
|
716
|
+
const name = readAttribute(attributes, SSML_ATTRS.NAME);
|
|
717
|
+
if (name !== void 0) element.name = name;
|
|
718
|
+
return finishElement(element, node, attributes);
|
|
719
|
+
}
|
|
720
|
+
case SSML_TAGS.BOOKMARK: {
|
|
721
|
+
const element = { type: SSML_TAGS.BOOKMARK };
|
|
722
|
+
const mark = readAttribute(attributes, SSML_ATTRS.MARK);
|
|
723
|
+
if (mark !== void 0) element.mark = mark;
|
|
724
|
+
return finishElement(element, node, attributes);
|
|
725
|
+
}
|
|
726
|
+
case SSML_TAGS.LEXICON: {
|
|
727
|
+
const element = { type: SSML_TAGS.LEXICON };
|
|
728
|
+
const uri = readAttribute(attributes, SSML_ATTRS.URI);
|
|
729
|
+
if (uri !== void 0) element.uri = uri;
|
|
730
|
+
return finishElement(element, node, attributes);
|
|
731
|
+
}
|
|
732
|
+
case SSML_TAGS.PARAGRAPH: {
|
|
733
|
+
const element = { type: SSML_TAGS.PARAGRAPH };
|
|
734
|
+
return finishElement(element, node, attributes);
|
|
735
|
+
}
|
|
736
|
+
case SSML_TAGS.SENTENCE: {
|
|
737
|
+
const element = { type: SSML_TAGS.SENTENCE };
|
|
738
|
+
return finishElement(element, node, attributes);
|
|
739
|
+
}
|
|
740
|
+
case SSML_TAGS.WORD: {
|
|
741
|
+
const element = { type: SSML_TAGS.WORD };
|
|
742
|
+
return finishElement(element, node, attributes);
|
|
743
|
+
}
|
|
744
|
+
case SSML_TAGS.MSTTS_SILENCE:
|
|
745
|
+
case SSML_TAGS.SILENCE: {
|
|
746
|
+
const element = {
|
|
747
|
+
type: node.name === SSML_TAGS.MSTTS_SILENCE ? SSML_TAGS.MSTTS_SILENCE : SSML_TAGS.SILENCE
|
|
748
|
+
};
|
|
749
|
+
const typeValue = readAttribute(attributes, SSML_ATTRS.TYPE);
|
|
750
|
+
const value = readAttribute(attributes, SSML_ATTRS.VALUE);
|
|
751
|
+
if (typeValue !== void 0) element.typeValue = typeValue;
|
|
752
|
+
if (value !== void 0) element.value = value;
|
|
753
|
+
return finishElement(element, node, attributes);
|
|
754
|
+
}
|
|
755
|
+
case SSML_TAGS.MSTTS_VISEME:
|
|
756
|
+
case SSML_TAGS.VISEME: {
|
|
757
|
+
const element = {
|
|
758
|
+
type: node.name === SSML_TAGS.MSTTS_VISEME ? SSML_TAGS.MSTTS_VISEME : SSML_TAGS.VISEME
|
|
759
|
+
};
|
|
760
|
+
const typeValue = readAttribute(attributes, SSML_ATTRS.TYPE);
|
|
761
|
+
if (typeValue !== void 0) element.typeValue = typeValue;
|
|
762
|
+
return finishElement(element, node, attributes);
|
|
763
|
+
}
|
|
764
|
+
default: {
|
|
765
|
+
const element = {
|
|
766
|
+
name: node.name,
|
|
767
|
+
type: "custom"
|
|
768
|
+
};
|
|
769
|
+
return finishElement(element, node, attributes);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
function convertNode(node) {
|
|
774
|
+
return typeof node === "string" ? node : convertElement(node);
|
|
775
|
+
}
|
|
776
|
+
function parseSsml(xmlString) {
|
|
777
|
+
if (typeof xmlString !== "string") {
|
|
778
|
+
throw new TypeError("SSML input must be a string");
|
|
779
|
+
}
|
|
780
|
+
const root = new XmlParser(xmlString).parse();
|
|
781
|
+
if (root.name !== SSML_TAGS.SPEAK) {
|
|
782
|
+
throw new Error(`SSML root element must be <${SSML_TAGS.SPEAK}>, found <${root.name}>`);
|
|
783
|
+
}
|
|
784
|
+
const attributes = { ...root.attributes };
|
|
785
|
+
const version = readAttribute(attributes, SSML_ATTRS.VERSION);
|
|
786
|
+
const lang = readAttribute(attributes, SSML_ATTRS.XML_LANG, SSML_ATTRS.LANG);
|
|
787
|
+
if (version === void 0) {
|
|
788
|
+
throw new Error(`SSML <${SSML_TAGS.SPEAK}> element is missing the "${SSML_ATTRS.VERSION}" attribute`);
|
|
789
|
+
}
|
|
790
|
+
if (lang === void 0) {
|
|
791
|
+
throw new Error(`SSML <${SSML_TAGS.SPEAK}> element is missing the "${SSML_ATTRS.XML_LANG}" attribute`);
|
|
792
|
+
}
|
|
793
|
+
removeStandardNamespaceAttributes(attributes);
|
|
794
|
+
const document2 = {
|
|
795
|
+
children: root.children.map(convertNode),
|
|
796
|
+
lang,
|
|
797
|
+
type: SSML_TAGS.SPEAK,
|
|
798
|
+
version
|
|
799
|
+
};
|
|
800
|
+
if (Object.keys(attributes).length > 0) {
|
|
801
|
+
document2.attributes = attributes;
|
|
802
|
+
}
|
|
803
|
+
return document2;
|
|
804
|
+
}
|
|
805
|
+
function escapeAttribute2(value) {
|
|
806
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">").replace(/'/g, "'");
|
|
807
|
+
}
|
|
808
|
+
function getPartialTextNodes(text, version, lang) {
|
|
809
|
+
if (!text.includes("<")) {
|
|
810
|
+
return [text];
|
|
811
|
+
}
|
|
812
|
+
try {
|
|
813
|
+
const openingTag = `<${SSML_TAGS.SPEAK} ${SSML_ATTRS.VERSION}="${escapeAttribute2(version)}" ${SSML_ATTRS.XMLNS}="${SYNTHESIS_NAMESPACE}" ${SSML_ATTRS.XML_LANG}="${escapeAttribute2(lang)}">`;
|
|
814
|
+
return parseSsml(`${openingTag}${text}</${SSML_TAGS.SPEAK}>`).children ?? [];
|
|
815
|
+
} catch {
|
|
816
|
+
return [{ type: "text", value: text }];
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
function getVoiceContext(context) {
|
|
820
|
+
const voice = context.voice;
|
|
821
|
+
if (typeof voice === "object" && voice !== null) {
|
|
822
|
+
return voice;
|
|
823
|
+
}
|
|
824
|
+
if (context.voiceName === void 0 && context.voiceEffect === void 0 && typeof voice !== "string") {
|
|
825
|
+
return void 0;
|
|
826
|
+
}
|
|
827
|
+
return {
|
|
828
|
+
name: context.voiceName ?? voice,
|
|
829
|
+
effect: context.voiceEffect
|
|
830
|
+
};
|
|
831
|
+
}
|
|
832
|
+
function serializePartialSsml(text, context) {
|
|
833
|
+
const version = context.version ?? DEFAULT_SSML_VERSION;
|
|
834
|
+
const lang = context.lang ?? DEFAULT_SSML_LANGUAGE;
|
|
835
|
+
let children = getPartialTextNodes(text, version, lang);
|
|
836
|
+
if (context.prosody) {
|
|
837
|
+
children = [
|
|
838
|
+
{
|
|
839
|
+
type: SSML_TAGS.PROSODY,
|
|
840
|
+
...context.prosody,
|
|
841
|
+
children
|
|
842
|
+
}
|
|
843
|
+
];
|
|
844
|
+
}
|
|
845
|
+
const voice = getVoiceContext(context);
|
|
846
|
+
if (voice) {
|
|
847
|
+
children = [
|
|
848
|
+
{
|
|
849
|
+
type: SSML_TAGS.VOICE,
|
|
850
|
+
...voice,
|
|
851
|
+
children
|
|
852
|
+
}
|
|
853
|
+
];
|
|
854
|
+
}
|
|
855
|
+
const document2 = {
|
|
856
|
+
type: SSML_TAGS.SPEAK,
|
|
857
|
+
version,
|
|
858
|
+
lang,
|
|
859
|
+
attributes: context.attributes,
|
|
860
|
+
children
|
|
861
|
+
};
|
|
862
|
+
return buildSsml(document2);
|
|
863
|
+
}
|
|
864
|
+
function buildPartialSsml(textOrOptions, context) {
|
|
865
|
+
if (typeof textOrOptions === "string") {
|
|
866
|
+
return serializePartialSsml(textOrOptions, context ?? {});
|
|
867
|
+
}
|
|
868
|
+
return serializePartialSsml(textOrOptions.text, textOrOptions);
|
|
869
|
+
}
|
|
870
|
+
var PARSER_POSITION_SUFFIX = / at position (\d+)$/;
|
|
871
|
+
function validateSsml(xmlString) {
|
|
872
|
+
try {
|
|
873
|
+
parseSsml(xmlString);
|
|
874
|
+
return null;
|
|
875
|
+
} catch (error) {
|
|
876
|
+
const rawMessage = error instanceof Error ? error.message : String(error);
|
|
877
|
+
const positionMatch = PARSER_POSITION_SUFFIX.exec(rawMessage);
|
|
878
|
+
return {
|
|
879
|
+
message: positionMatch ? rawMessage.slice(0, positionMatch.index) : rawMessage,
|
|
880
|
+
position: positionMatch ? Number.parseInt(positionMatch[1], 10) : 0
|
|
881
|
+
};
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
// packages/ssml-editor-react/src/buttonVisibility.ts
|
|
886
|
+
function isSsmlEditorButtonVisible(buttonVisibility, button) {
|
|
887
|
+
return buttonVisibility?.[button] !== false;
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
// packages/ssml-editor-react/src/clearSsmlDocument.ts
|
|
891
|
+
function getDocumentChildren(document2) {
|
|
892
|
+
return document2.children ?? (document2.content === void 0 ? [] : [document2.content]);
|
|
893
|
+
}
|
|
894
|
+
function appendNode(nodes, node) {
|
|
895
|
+
if (typeof node === "string") {
|
|
896
|
+
const lastNode = nodes[nodes.length - 1];
|
|
897
|
+
if (typeof lastNode === "string") {
|
|
898
|
+
nodes[nodes.length - 1] = lastNode + node;
|
|
899
|
+
} else if (node !== "") {
|
|
900
|
+
nodes.push(node);
|
|
901
|
+
}
|
|
902
|
+
return;
|
|
903
|
+
}
|
|
904
|
+
nodes.push(node);
|
|
905
|
+
}
|
|
906
|
+
function clearNodes(nodes) {
|
|
907
|
+
const clearedNodes = [];
|
|
908
|
+
for (const node of nodes) {
|
|
909
|
+
if (typeof node === "string") {
|
|
910
|
+
appendNode(clearedNodes, node);
|
|
911
|
+
continue;
|
|
912
|
+
}
|
|
913
|
+
if (node.type === "text") {
|
|
914
|
+
appendNode(clearedNodes, node.value);
|
|
915
|
+
continue;
|
|
916
|
+
}
|
|
917
|
+
const children = clearNodes(node.children ?? []);
|
|
918
|
+
if (node.type === "voice") {
|
|
919
|
+
appendNode(clearedNodes, { ...node, children });
|
|
920
|
+
continue;
|
|
921
|
+
}
|
|
922
|
+
for (const child of children) {
|
|
923
|
+
appendNode(clearedNodes, child);
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
return clearedNodes;
|
|
927
|
+
}
|
|
928
|
+
function clearSsmlDocument(document2) {
|
|
929
|
+
const nextDocument = {
|
|
930
|
+
...document2,
|
|
931
|
+
children: clearNodes(getDocumentChildren(document2))
|
|
932
|
+
};
|
|
933
|
+
if (nextDocument.content !== void 0) {
|
|
934
|
+
delete nextDocument.content;
|
|
935
|
+
}
|
|
936
|
+
return nextDocument;
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
// packages/ssml-editor-react/src/constants/ssmlPresets.ts
|
|
940
|
+
var ssmlPresets_exports = {};
|
|
941
|
+
__export(ssmlPresets_exports, {
|
|
942
|
+
BREAK_STRENGTH_PRESETS: () => BREAK_STRENGTH_PRESETS,
|
|
943
|
+
BREAK_TIME_DESCRIPTIONS: () => BREAK_TIME_DESCRIPTIONS,
|
|
944
|
+
BREAK_TIME_PRESETS: () => BREAK_TIME_PRESETS,
|
|
945
|
+
EMPHASIS_LEVEL_DESCRIPTIONS: () => EMPHASIS_LEVEL_DESCRIPTIONS,
|
|
946
|
+
EMPHASIS_LEVEL_PRESETS: () => EMPHASIS_LEVEL_PRESETS,
|
|
947
|
+
EXPRESS_AS_STYLE_DESCRIPTIONS: () => EXPRESS_AS_STYLE_DESCRIPTIONS,
|
|
948
|
+
EXPRESS_AS_STYLE_PRESETS: () => EXPRESS_AS_STYLE_PRESETS,
|
|
949
|
+
LANGUAGE_DESCRIPTIONS: () => LANGUAGE_DESCRIPTIONS,
|
|
950
|
+
LANGUAGE_PRESETS: () => LANGUAGE_PRESETS,
|
|
951
|
+
PHONEME_ALPHABET_PRESETS: () => PHONEME_ALPHABET_PRESETS,
|
|
952
|
+
PROSODY_PITCH_DESCRIPTIONS: () => PROSODY_PITCH_DESCRIPTIONS,
|
|
953
|
+
PROSODY_PITCH_PRESETS: () => PROSODY_PITCH_PRESETS,
|
|
954
|
+
PROSODY_RATE_DESCRIPTIONS: () => PROSODY_RATE_DESCRIPTIONS,
|
|
955
|
+
PROSODY_RATE_PRESETS: () => PROSODY_RATE_PRESETS,
|
|
956
|
+
PROSODY_RATE_VALUES: () => PROSODY_RATE_VALUES,
|
|
957
|
+
PROSODY_VOLUME_DESCRIPTIONS: () => PROSODY_VOLUME_DESCRIPTIONS,
|
|
958
|
+
PROSODY_VOLUME_PRESETS: () => PROSODY_VOLUME_PRESETS,
|
|
959
|
+
SAY_AS_DESCRIPTIONS: () => SAY_AS_DESCRIPTIONS,
|
|
960
|
+
SAY_AS_PRESETS: () => SAY_AS_PRESETS,
|
|
961
|
+
SILENCE_TYPE_PRESETS: () => SILENCE_TYPE_PRESETS,
|
|
962
|
+
SILENCE_VALUE_DESCRIPTIONS: () => SILENCE_VALUE_DESCRIPTIONS,
|
|
963
|
+
SILENCE_VALUE_PRESETS: () => SILENCE_VALUE_PRESETS,
|
|
964
|
+
SSML_PRESETS: () => SSML_PRESETS,
|
|
965
|
+
SSML_PRESET_EXAMPLES: () => SSML_PRESET_EXAMPLES,
|
|
966
|
+
VISEME_TYPE_PRESETS: () => VISEME_TYPE_PRESETS
|
|
967
|
+
});
|
|
968
|
+
var SSML_PRESETS = [
|
|
969
|
+
{
|
|
970
|
+
id: "basic",
|
|
971
|
+
label: "Basic speech",
|
|
972
|
+
ssml: '<speak version="1.0" xml:lang="en-US">Hello, world!</speak>',
|
|
973
|
+
description: "A minimal SSML document."
|
|
974
|
+
},
|
|
975
|
+
{
|
|
976
|
+
id: "voice",
|
|
977
|
+
label: "Voice selection",
|
|
978
|
+
ssml: '<speak version="1.0" xml:lang="en-US"><voice name="en-US-JennyNeural">Hello, world!</voice></speak>',
|
|
979
|
+
description: "Speaks text with a selected voice."
|
|
980
|
+
},
|
|
981
|
+
{
|
|
982
|
+
id: "prosody",
|
|
983
|
+
label: "Prosody",
|
|
984
|
+
ssml: '<speak version="1.0" xml:lang="en-US"><prosody rate="fast" pitch="+2st">Hello, world!</prosody></speak>',
|
|
985
|
+
description: "Adjusts the speech rate and pitch."
|
|
986
|
+
}
|
|
987
|
+
];
|
|
988
|
+
var BREAK_TIME_PRESETS = ["500ms", "1s", "2s", "3s"];
|
|
989
|
+
var BREAK_STRENGTH_PRESETS = ["none", "x-weak", "weak", "medium", "strong", "x-strong"];
|
|
990
|
+
var PROSODY_RATE_PRESETS = ["x-slow", "slow", "medium", "fast", "x-fast"];
|
|
991
|
+
var PROSODY_RATE_VALUES = [...PROSODY_RATE_PRESETS, "percentage"];
|
|
992
|
+
var PROSODY_PITCH_PRESETS = ["+2st", "-2st", "0st", "+4st", "-4st", "+8st", "-8st", "+12st", "-12st"];
|
|
993
|
+
var PROSODY_VOLUME_PRESETS = ["silent", "x-soft", "soft", "medium", "loud", "x-loud"];
|
|
994
|
+
var EXPRESS_AS_STYLE_PRESETS = ["cheerful", "friendly", "calm", "sad", "angry", "excited", "serious"];
|
|
995
|
+
var EMPHASIS_LEVEL_PRESETS = ["strong", "moderate", "reduced", "none"];
|
|
996
|
+
var SAY_AS_PRESETS = [
|
|
997
|
+
"characters",
|
|
998
|
+
"spell-out",
|
|
999
|
+
"cardinal",
|
|
1000
|
+
"ordinal",
|
|
1001
|
+
"number",
|
|
1002
|
+
"date",
|
|
1003
|
+
"time",
|
|
1004
|
+
"telephone",
|
|
1005
|
+
"fraction",
|
|
1006
|
+
"address",
|
|
1007
|
+
"name",
|
|
1008
|
+
"currency"
|
|
1009
|
+
];
|
|
1010
|
+
var LANGUAGE_PRESETS = ["ja-JP", "en-US", "de-DE", "fr-FR"];
|
|
1011
|
+
var SILENCE_VALUE_PRESETS = ["300ms", "500ms", "1s"];
|
|
1012
|
+
var SILENCE_TYPE_PRESETS = [
|
|
1013
|
+
"Leading",
|
|
1014
|
+
"Tailing",
|
|
1015
|
+
"Sentenceboundary",
|
|
1016
|
+
"Comma",
|
|
1017
|
+
"Semicolon",
|
|
1018
|
+
"Enumerationcomma"
|
|
1019
|
+
];
|
|
1020
|
+
var PHONEME_ALPHABET_PRESETS = ["ipa", "sapi", "ups", "x-sampa"];
|
|
1021
|
+
var VISEME_TYPE_PRESETS = ["redlips_front", "FacialExpression"];
|
|
1022
|
+
var SSML_PRESET_EXAMPLES = {
|
|
1023
|
+
breakTime: "500ms",
|
|
1024
|
+
prosodyRate: "fast",
|
|
1025
|
+
prosodyPitch: "+2st",
|
|
1026
|
+
prosodyVolume: "loud",
|
|
1027
|
+
expressAsStyle: "cheerful",
|
|
1028
|
+
phonemeAlphabet: "ipa",
|
|
1029
|
+
silenceValue: "300ms"
|
|
1030
|
+
};
|
|
1031
|
+
var BREAK_TIME_DESCRIPTIONS = {
|
|
1032
|
+
"500ms": {
|
|
1033
|
+
ja: "500\u30DF\u30EA\u79D2\u306E\u7121\u97F3",
|
|
1034
|
+
en: "Inserts 500 milliseconds of silence."
|
|
1035
|
+
},
|
|
1036
|
+
"1s": {
|
|
1037
|
+
ja: "1\u79D2\u306E\u7121\u97F3",
|
|
1038
|
+
en: "Inserts one second of silence."
|
|
1039
|
+
},
|
|
1040
|
+
"2s": {
|
|
1041
|
+
ja: "2\u79D2\u306E\u7121\u97F3",
|
|
1042
|
+
en: "Inserts two seconds of silence."
|
|
1043
|
+
},
|
|
1044
|
+
"3s": {
|
|
1045
|
+
ja: "3\u79D2\u306E\u7121\u97F3",
|
|
1046
|
+
en: "Inserts three seconds of silence."
|
|
1047
|
+
}
|
|
1048
|
+
};
|
|
1049
|
+
var EMPHASIS_LEVEL_DESCRIPTIONS = {
|
|
1050
|
+
strong: {
|
|
1051
|
+
ja: "\u5F37\u3044\u5F37\u8ABF",
|
|
1052
|
+
en: "Applies strong emphasis."
|
|
1053
|
+
},
|
|
1054
|
+
moderate: {
|
|
1055
|
+
ja: "\u4E2D\u7A0B\u5EA6\u306E\u5F37\u8ABF",
|
|
1056
|
+
en: "Applies moderate emphasis."
|
|
1057
|
+
},
|
|
1058
|
+
reduced: {
|
|
1059
|
+
ja: "\u5F31\u3081\u306E\u5F37\u8ABF",
|
|
1060
|
+
en: "Applies reduced emphasis."
|
|
1061
|
+
},
|
|
1062
|
+
none: {
|
|
1063
|
+
ja: "\u5F37\u8ABF\u306A\u3057",
|
|
1064
|
+
en: "Applies no emphasis."
|
|
1065
|
+
}
|
|
1066
|
+
};
|
|
1067
|
+
var PROSODY_RATE_DESCRIPTIONS = {
|
|
1068
|
+
"x-slow": {
|
|
1069
|
+
ja: "\u6700\u3082\u9045\u3044\u901F\u5EA6",
|
|
1070
|
+
en: "Uses the slowest speech rate."
|
|
1071
|
+
},
|
|
1072
|
+
slow: {
|
|
1073
|
+
ja: "\u9045\u3044\u901F\u5EA6",
|
|
1074
|
+
en: "Uses a slow speech rate."
|
|
1075
|
+
},
|
|
1076
|
+
medium: {
|
|
1077
|
+
ja: "\u6A19\u6E96\u7684\u306A\u901F\u5EA6",
|
|
1078
|
+
en: "Uses the standard speech rate."
|
|
1079
|
+
},
|
|
1080
|
+
fast: {
|
|
1081
|
+
ja: "\u901F\u3044\u901F\u5EA6",
|
|
1082
|
+
en: "Uses a fast speech rate."
|
|
1083
|
+
},
|
|
1084
|
+
"x-fast": {
|
|
1085
|
+
ja: "\u6700\u3082\u901F\u3044\u901F\u5EA6",
|
|
1086
|
+
en: "Uses the fastest speech rate."
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
var PROSODY_PITCH_DESCRIPTIONS = {
|
|
1090
|
+
"+2st": {
|
|
1091
|
+
ja: "\u57FA\u6E96\u306E\u58F0\u306E\u9AD8\u3055\u3088\u308A2\u534A\u97F3\u4E0A",
|
|
1092
|
+
en: "Raises the pitch by two semitones."
|
|
1093
|
+
},
|
|
1094
|
+
"-2st": {
|
|
1095
|
+
ja: "\u57FA\u6E96\u306E\u58F0\u306E\u9AD8\u3055\u3088\u308A2\u534A\u97F3\u4E0B",
|
|
1096
|
+
en: "Lowers the pitch by two semitones."
|
|
1097
|
+
},
|
|
1098
|
+
"0st": {
|
|
1099
|
+
ja: "\u57FA\u6E96\u306E\u58F0\u306E\u9AD8\u3055",
|
|
1100
|
+
en: "Keeps the baseline pitch."
|
|
1101
|
+
},
|
|
1102
|
+
"+4st": {
|
|
1103
|
+
ja: "\u57FA\u6E96\u306E\u58F0\u306E\u9AD8\u3055\u3088\u308A4\u534A\u97F3\u4E0A",
|
|
1104
|
+
en: "Raises the pitch by four semitones."
|
|
1105
|
+
},
|
|
1106
|
+
"-4st": {
|
|
1107
|
+
ja: "\u57FA\u6E96\u306E\u58F0\u306E\u9AD8\u3055\u3088\u308A4\u534A\u97F3\u4E0B",
|
|
1108
|
+
en: "Lowers the pitch by four semitones."
|
|
1109
|
+
},
|
|
1110
|
+
"+8st": {
|
|
1111
|
+
ja: "\u57FA\u6E96\u306E\u58F0\u306E\u9AD8\u3055\u3088\u308A8\u534A\u97F3\u4E0A",
|
|
1112
|
+
en: "Raises the pitch by eight semitones."
|
|
1113
|
+
},
|
|
1114
|
+
"-8st": {
|
|
1115
|
+
ja: "\u57FA\u6E96\u306E\u58F0\u306E\u9AD8\u3055\u3088\u308A8\u534A\u97F3\u4E0B",
|
|
1116
|
+
en: "Lowers the pitch by eight semitones."
|
|
1117
|
+
},
|
|
1118
|
+
"+12st": {
|
|
1119
|
+
ja: "\u57FA\u6E96\u306E\u58F0\u306E\u9AD8\u3055\u3088\u308A12\u534A\u97F3\u4E0A",
|
|
1120
|
+
en: "Raises the pitch by twelve semitones."
|
|
1121
|
+
},
|
|
1122
|
+
"-12st": {
|
|
1123
|
+
ja: "\u57FA\u6E96\u306E\u58F0\u306E\u9AD8\u3055\u3088\u308A12\u534A\u97F3\u4E0B",
|
|
1124
|
+
en: "Lowers the pitch by twelve semitones."
|
|
1125
|
+
}
|
|
1126
|
+
};
|
|
1127
|
+
var PROSODY_VOLUME_DESCRIPTIONS = {
|
|
1128
|
+
silent: {
|
|
1129
|
+
ja: "\u7121\u97F3",
|
|
1130
|
+
en: "Makes the selected text silent."
|
|
1131
|
+
},
|
|
1132
|
+
"x-soft": {
|
|
1133
|
+
ja: "\u6700\u3082\u5C0F\u3055\u3044\u97F3\u91CF",
|
|
1134
|
+
en: "Uses the quietest volume."
|
|
1135
|
+
},
|
|
1136
|
+
soft: {
|
|
1137
|
+
ja: "\u5C0F\u3055\u3044\u97F3\u91CF",
|
|
1138
|
+
en: "Uses a soft volume."
|
|
1139
|
+
},
|
|
1140
|
+
medium: {
|
|
1141
|
+
ja: "\u6A19\u6E96\u7684\u306A\u97F3\u91CF",
|
|
1142
|
+
en: "Uses the standard volume."
|
|
1143
|
+
},
|
|
1144
|
+
loud: {
|
|
1145
|
+
ja: "\u5927\u304D\u3044\u97F3\u91CF",
|
|
1146
|
+
en: "Uses a loud volume."
|
|
1147
|
+
},
|
|
1148
|
+
"x-loud": {
|
|
1149
|
+
ja: "\u6700\u3082\u5927\u304D\u3044\u97F3\u91CF",
|
|
1150
|
+
en: "Uses the loudest volume."
|
|
1151
|
+
}
|
|
1152
|
+
};
|
|
1153
|
+
var EXPRESS_AS_STYLE_DESCRIPTIONS = {
|
|
1154
|
+
cheerful: {
|
|
1155
|
+
ja: "\u660E\u308B\u304F\u5143\u6C17\u306A\u30B9\u30BF\u30A4\u30EB",
|
|
1156
|
+
en: "Uses a cheerful style."
|
|
1157
|
+
},
|
|
1158
|
+
friendly: {
|
|
1159
|
+
ja: "\u89AA\u3057\u307F\u3084\u3059\u3044\u30B9\u30BF\u30A4\u30EB",
|
|
1160
|
+
en: "Uses a friendly style."
|
|
1161
|
+
},
|
|
1162
|
+
calm: {
|
|
1163
|
+
ja: "\u7A4F\u3084\u304B\u306A\u30B9\u30BF\u30A4\u30EB",
|
|
1164
|
+
en: "Uses a calm style."
|
|
1165
|
+
},
|
|
1166
|
+
sad: {
|
|
1167
|
+
ja: "\u60B2\u3057\u3052\u306A\u30B9\u30BF\u30A4\u30EB",
|
|
1168
|
+
en: "Uses a sad style."
|
|
1169
|
+
},
|
|
1170
|
+
angry: {
|
|
1171
|
+
ja: "\u6012\u3063\u305F\u3088\u3046\u306A\u30B9\u30BF\u30A4\u30EB",
|
|
1172
|
+
en: "Uses an angry style."
|
|
1173
|
+
},
|
|
1174
|
+
excited: {
|
|
1175
|
+
ja: "\u8208\u596E\u3057\u305F\u30B9\u30BF\u30A4\u30EB",
|
|
1176
|
+
en: "Uses an excited style."
|
|
1177
|
+
},
|
|
1178
|
+
serious: {
|
|
1179
|
+
ja: "\u771F\u5263\u306A\u30B9\u30BF\u30A4\u30EB",
|
|
1180
|
+
en: "Uses a serious style."
|
|
1181
|
+
}
|
|
1182
|
+
};
|
|
1183
|
+
var SAY_AS_DESCRIPTIONS = {
|
|
1184
|
+
characters: {
|
|
1185
|
+
ja: "1\u6587\u5B57\u305A\u3064\u306E\u8AAD\u307F\u4E0A\u3052",
|
|
1186
|
+
en: "Speaks the characters one by one."
|
|
1187
|
+
},
|
|
1188
|
+
"spell-out": {
|
|
1189
|
+
ja: "\u7DB4\u308A\u306E\u8AAD\u307F\u4E0A\u3052\uFF081\u6587\u5B57\u305A\u3064\uFF09",
|
|
1190
|
+
en: "Spells out the text character by character."
|
|
1191
|
+
},
|
|
1192
|
+
cardinal: {
|
|
1193
|
+
ja: "\u57FA\u6570\u3068\u3057\u3066\u306E\u8AAD\u307F\u4E0A\u3052",
|
|
1194
|
+
en: "Speaks the value as a cardinal number."
|
|
1195
|
+
},
|
|
1196
|
+
ordinal: {
|
|
1197
|
+
ja: "\u5E8F\u6570\u3068\u3057\u3066\u306E\u8AAD\u307F\u4E0A\u3052",
|
|
1198
|
+
en: "Speaks the value as an ordinal number."
|
|
1199
|
+
},
|
|
1200
|
+
number: {
|
|
1201
|
+
ja: "\u6570\u5024\u3068\u3057\u3066\u306E\u8AAD\u307F\u4E0A\u3052",
|
|
1202
|
+
en: "Speaks the value as a number."
|
|
1203
|
+
},
|
|
1204
|
+
date: {
|
|
1205
|
+
ja: "\u65E5\u4ED8\u3068\u3057\u3066\u306E\u8AAD\u307F\u4E0A\u3052",
|
|
1206
|
+
en: "Speaks the value as a date."
|
|
1207
|
+
},
|
|
1208
|
+
time: {
|
|
1209
|
+
ja: "\u6642\u523B\u3068\u3057\u3066\u306E\u8AAD\u307F\u4E0A\u3052",
|
|
1210
|
+
en: "Speaks the value as a time."
|
|
1211
|
+
},
|
|
1212
|
+
telephone: {
|
|
1213
|
+
ja: "\u96FB\u8A71\u756A\u53F7\u3068\u3057\u3066\u306E\u8AAD\u307F\u4E0A\u3052",
|
|
1214
|
+
en: "Speaks the value as a telephone number."
|
|
1215
|
+
},
|
|
1216
|
+
fraction: {
|
|
1217
|
+
ja: "\u5206\u6570\u3068\u3057\u3066\u306E\u8AAD\u307F\u4E0A\u3052",
|
|
1218
|
+
en: "Speaks the value as a fraction."
|
|
1219
|
+
},
|
|
1220
|
+
address: {
|
|
1221
|
+
ja: "\u4F4F\u6240\u3068\u3057\u3066\u306E\u8AAD\u307F\u4E0A\u3052",
|
|
1222
|
+
en: "Speaks the value as an address."
|
|
1223
|
+
},
|
|
1224
|
+
name: {
|
|
1225
|
+
ja: "\u540D\u524D\u3068\u3057\u3066\u306E\u8AAD\u307F\u4E0A\u3052",
|
|
1226
|
+
en: "Speaks the value as a name."
|
|
1227
|
+
},
|
|
1228
|
+
currency: {
|
|
1229
|
+
ja: "\u901A\u8CA8\u3068\u3057\u3066\u306E\u8AAD\u307F\u4E0A\u3052",
|
|
1230
|
+
en: "Speaks the value as currency."
|
|
1231
|
+
}
|
|
1232
|
+
};
|
|
1233
|
+
var LANGUAGE_DESCRIPTIONS = {
|
|
1234
|
+
"ja-JP": {
|
|
1235
|
+
ja: "\u65E5\u672C\u8A9E\uFF08\u65E5\u672C\uFF09\u3067\u8AAD\u307F\u4E0A\u3052\u307E\u3059\u3002",
|
|
1236
|
+
en: "Speaks the text in Japanese (Japan)."
|
|
1237
|
+
},
|
|
1238
|
+
"en-US": {
|
|
1239
|
+
ja: "\u82F1\u8A9E\uFF08\u7C73\u56FD\uFF09\u3067\u8AAD\u307F\u4E0A\u3052\u307E\u3059\u3002",
|
|
1240
|
+
en: "Speaks the text in English (United States)."
|
|
1241
|
+
},
|
|
1242
|
+
"de-DE": {
|
|
1243
|
+
ja: "\u30C9\u30A4\u30C4\u8A9E\uFF08\u30C9\u30A4\u30C4\uFF09\u3067\u8AAD\u307F\u4E0A\u3052\u307E\u3059\u3002",
|
|
1244
|
+
en: "Speaks the text in German (Germany)."
|
|
1245
|
+
},
|
|
1246
|
+
"fr-FR": {
|
|
1247
|
+
ja: "\u30D5\u30E9\u30F3\u30B9\u8A9E\uFF08\u30D5\u30E9\u30F3\u30B9\uFF09\u3067\u8AAD\u307F\u4E0A\u3052\u307E\u3059\u3002",
|
|
1248
|
+
en: "Speaks the text in French (France)."
|
|
1249
|
+
}
|
|
1250
|
+
};
|
|
1251
|
+
var SILENCE_VALUE_DESCRIPTIONS = {
|
|
1252
|
+
"300ms": {
|
|
1253
|
+
ja: "\u5148\u982D\u306B300\u30DF\u30EA\u79D2\u306E\u7121\u97F3\u3092\u633F\u5165\u3057\u307E\u3059\u3002",
|
|
1254
|
+
en: "Inserts 300 milliseconds of leading silence."
|
|
1255
|
+
},
|
|
1256
|
+
"500ms": {
|
|
1257
|
+
ja: "\u5148\u982D\u306B500\u30DF\u30EA\u79D2\u306E\u7121\u97F3\u3092\u633F\u5165\u3057\u307E\u3059\u3002",
|
|
1258
|
+
en: "Inserts 500 milliseconds of leading silence."
|
|
1259
|
+
},
|
|
1260
|
+
"1s": {
|
|
1261
|
+
ja: "\u5148\u982D\u306B1\u79D2\u306E\u7121\u97F3\u3092\u633F\u5165\u3057\u307E\u3059\u3002",
|
|
1262
|
+
en: "Inserts one second of leading silence."
|
|
1263
|
+
}
|
|
1264
|
+
};
|
|
1265
|
+
|
|
1266
|
+
// packages/ssml-editor-react/src/formatXml.ts
|
|
1267
|
+
var INDENT = " ";
|
|
1268
|
+
var FRAGMENT_ROOT = "ssml-builder-fragment";
|
|
1269
|
+
var XML_ENTITY_NAMES = /* @__PURE__ */ new Set(["amp", "apos", "gt", "lt", "quot"]);
|
|
1270
|
+
function isXmlNameStart2(value) {
|
|
1271
|
+
return value !== void 0 && /[A-Za-z_]/.test(value);
|
|
1272
|
+
}
|
|
1273
|
+
function isXmlNameCharacter2(value) {
|
|
1274
|
+
return value !== void 0 && /[A-Za-z0-9_.:-]/.test(value);
|
|
1275
|
+
}
|
|
1276
|
+
function isXmlWhitespace2(value) {
|
|
1277
|
+
return value === " " || value === " " || value === "\r" || value === "\n";
|
|
1278
|
+
}
|
|
1279
|
+
function fail(message) {
|
|
1280
|
+
throw new Error(message);
|
|
1281
|
+
}
|
|
1282
|
+
function skipWhitespace(source, index) {
|
|
1283
|
+
while (isXmlWhitespace2(source[index])) {
|
|
1284
|
+
index += 1;
|
|
1285
|
+
}
|
|
1286
|
+
return index;
|
|
1287
|
+
}
|
|
1288
|
+
function readName(source, start, end) {
|
|
1289
|
+
if (!isXmlNameStart2(source[start])) {
|
|
1290
|
+
fail("Invalid XML name");
|
|
1291
|
+
}
|
|
1292
|
+
let index = start + 1;
|
|
1293
|
+
while (index < end && isXmlNameCharacter2(source[index])) {
|
|
1294
|
+
index += 1;
|
|
1295
|
+
}
|
|
1296
|
+
return { name: source.slice(start, index), index };
|
|
1297
|
+
}
|
|
1298
|
+
function validateCharacterReference(entity) {
|
|
1299
|
+
const isHexadecimal = entity.startsWith("#x") || entity.startsWith("#X");
|
|
1300
|
+
const isDecimal = entity.startsWith("#");
|
|
1301
|
+
if (!isHexadecimal && !isDecimal) {
|
|
1302
|
+
if (!XML_ENTITY_NAMES.has(entity)) {
|
|
1303
|
+
fail(`Unknown XML entity: &${entity};`);
|
|
1304
|
+
}
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
const digits = entity.slice(isHexadecimal ? 2 : 1);
|
|
1308
|
+
const validDigits = isHexadecimal ? /^[0-9A-Fa-f]+$/.test(digits) : /^[0-9]+$/.test(digits);
|
|
1309
|
+
const codePoint = Number.parseInt(digits, isHexadecimal ? 16 : 10);
|
|
1310
|
+
if (!validDigits || !Number.isInteger(codePoint) || codePoint < 0 || codePoint > 1114111 || codePoint >= 55296 && codePoint <= 57343 || codePoint < 32 && ![9, 10, 13].includes(codePoint)) {
|
|
1311
|
+
fail(`Invalid XML character reference: &${entity};`);
|
|
1312
|
+
}
|
|
1313
|
+
}
|
|
1314
|
+
function validateEntityReferences(value) {
|
|
1315
|
+
let index = 0;
|
|
1316
|
+
while (true) {
|
|
1317
|
+
const ampersand = value.indexOf("&", index);
|
|
1318
|
+
if (ampersand === -1) {
|
|
1319
|
+
return;
|
|
1320
|
+
}
|
|
1321
|
+
const semicolon = value.indexOf(";", ampersand + 1);
|
|
1322
|
+
if (semicolon === -1) {
|
|
1323
|
+
fail("Unterminated XML entity reference");
|
|
1324
|
+
}
|
|
1325
|
+
validateCharacterReference(value.slice(ampersand + 1, semicolon));
|
|
1326
|
+
index = semicolon + 1;
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
function findTagEnd(source, start, hasInternalSubset = false) {
|
|
1330
|
+
let quote;
|
|
1331
|
+
let subsetDepth = 0;
|
|
1332
|
+
for (let index = start + 1; index < source.length; index += 1) {
|
|
1333
|
+
const character = source[index];
|
|
1334
|
+
if (quote !== void 0) {
|
|
1335
|
+
if (character === quote) {
|
|
1336
|
+
quote = void 0;
|
|
1337
|
+
}
|
|
1338
|
+
continue;
|
|
1339
|
+
}
|
|
1340
|
+
if (character === '"' || character === "'") {
|
|
1341
|
+
quote = character;
|
|
1342
|
+
continue;
|
|
1343
|
+
}
|
|
1344
|
+
if (hasInternalSubset) {
|
|
1345
|
+
if (character === "[") {
|
|
1346
|
+
subsetDepth += 1;
|
|
1347
|
+
continue;
|
|
1348
|
+
}
|
|
1349
|
+
if (character === "]" && subsetDepth > 0) {
|
|
1350
|
+
subsetDepth -= 1;
|
|
1351
|
+
continue;
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
if (character === ">" && subsetDepth === 0) {
|
|
1355
|
+
return index;
|
|
1356
|
+
}
|
|
1357
|
+
}
|
|
1358
|
+
fail("Unclosed XML markup");
|
|
1359
|
+
}
|
|
1360
|
+
function parseStartTag(source, start, end) {
|
|
1361
|
+
const nameResult = readName(source, start + 1, end);
|
|
1362
|
+
let index = nameResult.index;
|
|
1363
|
+
let hasAttribute = false;
|
|
1364
|
+
const attributeNames = /* @__PURE__ */ new Set();
|
|
1365
|
+
while (index < end) {
|
|
1366
|
+
const beforeWhitespace = index;
|
|
1367
|
+
index = skipWhitespace(source, index);
|
|
1368
|
+
if (index === end) {
|
|
1369
|
+
break;
|
|
1370
|
+
}
|
|
1371
|
+
if (source[index] === "/") {
|
|
1372
|
+
if (index + 1 !== end) {
|
|
1373
|
+
fail("Invalid XML self-closing tag");
|
|
1374
|
+
}
|
|
1375
|
+
return { name: nameResult.name, selfClosing: true };
|
|
1376
|
+
}
|
|
1377
|
+
if (hasAttribute && beforeWhitespace === index) {
|
|
1378
|
+
fail("XML attributes must be separated by whitespace");
|
|
1379
|
+
}
|
|
1380
|
+
const attribute = readName(source, index, end);
|
|
1381
|
+
index = skipWhitespace(source, attribute.index);
|
|
1382
|
+
if (source[index] !== "=") {
|
|
1383
|
+
fail(`XML attribute ${attribute.name} must have a value`);
|
|
1384
|
+
}
|
|
1385
|
+
index = skipWhitespace(source, index + 1);
|
|
1386
|
+
const quote = source[index];
|
|
1387
|
+
if (quote !== '"' && quote !== "'") {
|
|
1388
|
+
fail(`XML attribute ${attribute.name} must use a quoted value`);
|
|
1389
|
+
}
|
|
1390
|
+
index += 1;
|
|
1391
|
+
const valueStart = index;
|
|
1392
|
+
while (index < end && source[index] !== quote) {
|
|
1393
|
+
if (source[index] === "<") {
|
|
1394
|
+
fail(`Invalid "<" in XML attribute ${attribute.name}`);
|
|
1395
|
+
}
|
|
1396
|
+
index += 1;
|
|
1397
|
+
}
|
|
1398
|
+
if (index === end) {
|
|
1399
|
+
fail(`Unclosed XML attribute ${attribute.name}`);
|
|
1400
|
+
}
|
|
1401
|
+
if (attributeNames.has(attribute.name)) {
|
|
1402
|
+
fail(`Duplicate XML attribute: ${attribute.name}`);
|
|
1403
|
+
}
|
|
1404
|
+
attributeNames.add(attribute.name);
|
|
1405
|
+
validateEntityReferences(source.slice(valueStart, index));
|
|
1406
|
+
index += 1;
|
|
1407
|
+
hasAttribute = true;
|
|
1408
|
+
}
|
|
1409
|
+
return { name: nameResult.name, selfClosing: false };
|
|
1410
|
+
}
|
|
1411
|
+
function parseClosingTag(source, start, end) {
|
|
1412
|
+
const nameResult = readName(source, start + 2, end);
|
|
1413
|
+
if (skipWhitespace(source, nameResult.index) !== end) {
|
|
1414
|
+
fail("Invalid XML closing tag");
|
|
1415
|
+
}
|
|
1416
|
+
return nameResult.name;
|
|
1417
|
+
}
|
|
1418
|
+
function parseProcessingInstruction(source, start, end) {
|
|
1419
|
+
readName(source, start + 2, end);
|
|
1420
|
+
}
|
|
1421
|
+
function parseDeclaration(source, start, end) {
|
|
1422
|
+
readName(source, start + 2, end);
|
|
1423
|
+
}
|
|
1424
|
+
function appendNode2(nodes, node) {
|
|
1425
|
+
const previous = nodes[nodes.length - 1];
|
|
1426
|
+
if (node.kind === "text" && previous?.kind === "text") {
|
|
1427
|
+
previous.value += node.value;
|
|
1428
|
+
return;
|
|
1429
|
+
}
|
|
1430
|
+
nodes.push(node);
|
|
1431
|
+
}
|
|
1432
|
+
function currentElement(stack) {
|
|
1433
|
+
return stack[stack.length - 1];
|
|
1434
|
+
}
|
|
1435
|
+
function parseXml(source) {
|
|
1436
|
+
const children = [];
|
|
1437
|
+
const stack = [];
|
|
1438
|
+
let root;
|
|
1439
|
+
let index = 0;
|
|
1440
|
+
while (index < source.length) {
|
|
1441
|
+
if (source[index] !== "<") {
|
|
1442
|
+
const textStart = index;
|
|
1443
|
+
while (index < source.length && source[index] !== "<") {
|
|
1444
|
+
index += 1;
|
|
1445
|
+
}
|
|
1446
|
+
const value = source.slice(textStart, index);
|
|
1447
|
+
if (value.includes("]]>")) {
|
|
1448
|
+
fail("CDATA termination is not valid in ordinary XML text");
|
|
1449
|
+
}
|
|
1450
|
+
validateEntityReferences(value);
|
|
1451
|
+
if (stack.length === 0 && value.trim() !== "") {
|
|
1452
|
+
fail("Unexpected text outside the root XML element");
|
|
1453
|
+
}
|
|
1454
|
+
appendNode2(currentElement(stack)?.children ?? children, { kind: "text", value });
|
|
1455
|
+
continue;
|
|
1456
|
+
}
|
|
1457
|
+
if (source.startsWith("<!--", index)) {
|
|
1458
|
+
const end2 = source.indexOf("-->", index + 4);
|
|
1459
|
+
if (end2 === -1) {
|
|
1460
|
+
fail("Unclosed XML comment");
|
|
1461
|
+
}
|
|
1462
|
+
const content = source.slice(index + 4, end2);
|
|
1463
|
+
if (content.includes("--") || content.endsWith("-")) {
|
|
1464
|
+
fail("Invalid XML comment");
|
|
1465
|
+
}
|
|
1466
|
+
appendNode2(currentElement(stack)?.children ?? children, {
|
|
1467
|
+
kind: "comment",
|
|
1468
|
+
raw: source.slice(index, end2 + 3)
|
|
1469
|
+
});
|
|
1470
|
+
index = end2 + 3;
|
|
1471
|
+
continue;
|
|
1472
|
+
}
|
|
1473
|
+
if (source.startsWith("<![CDATA[", index)) {
|
|
1474
|
+
const end2 = source.indexOf("]]>", index + "<![CDATA[".length);
|
|
1475
|
+
if (end2 === -1) {
|
|
1476
|
+
fail("Unclosed XML CDATA section");
|
|
1477
|
+
}
|
|
1478
|
+
if (stack.length === 0) {
|
|
1479
|
+
fail("CDATA is not allowed outside the root XML element");
|
|
1480
|
+
}
|
|
1481
|
+
appendNode2(currentElement(stack)?.children ?? children, {
|
|
1482
|
+
kind: "cdata",
|
|
1483
|
+
raw: source.slice(index, end2 + 3)
|
|
1484
|
+
});
|
|
1485
|
+
index = end2 + 3;
|
|
1486
|
+
continue;
|
|
1487
|
+
}
|
|
1488
|
+
if (source.startsWith("<?", index)) {
|
|
1489
|
+
const end2 = source.indexOf("?>", index + 2);
|
|
1490
|
+
if (end2 === -1) {
|
|
1491
|
+
fail("Unclosed XML processing instruction");
|
|
1492
|
+
}
|
|
1493
|
+
parseProcessingInstruction(source, index, end2);
|
|
1494
|
+
appendNode2(currentElement(stack)?.children ?? children, {
|
|
1495
|
+
kind: "processing-instruction",
|
|
1496
|
+
raw: source.slice(index, end2 + 2)
|
|
1497
|
+
});
|
|
1498
|
+
index = end2 + 2;
|
|
1499
|
+
continue;
|
|
1500
|
+
}
|
|
1501
|
+
if (source.startsWith("</", index)) {
|
|
1502
|
+
const end2 = findTagEnd(source, index);
|
|
1503
|
+
const name2 = parseClosingTag(source, index, end2);
|
|
1504
|
+
const element = currentElement(stack);
|
|
1505
|
+
if (element === void 0 || element.name !== name2) {
|
|
1506
|
+
fail(`Mismatched closing XML element: </${name2}>`);
|
|
1507
|
+
}
|
|
1508
|
+
element.close = source.slice(index, end2 + 1);
|
|
1509
|
+
stack.pop();
|
|
1510
|
+
index = end2 + 1;
|
|
1511
|
+
continue;
|
|
1512
|
+
}
|
|
1513
|
+
if (source.startsWith("<!", index)) {
|
|
1514
|
+
const end2 = findTagEnd(source, index, true);
|
|
1515
|
+
parseDeclaration(source, index, end2);
|
|
1516
|
+
appendNode2(currentElement(stack)?.children ?? children, {
|
|
1517
|
+
kind: "declaration",
|
|
1518
|
+
raw: source.slice(index, end2 + 1)
|
|
1519
|
+
});
|
|
1520
|
+
index = end2 + 1;
|
|
1521
|
+
continue;
|
|
1522
|
+
}
|
|
1523
|
+
const end = findTagEnd(source, index);
|
|
1524
|
+
const { name, selfClosing } = parseStartTag(source, index, end);
|
|
1525
|
+
if (stack.length === 0) {
|
|
1526
|
+
if (root !== void 0) {
|
|
1527
|
+
fail("Multiple root XML elements are not allowed");
|
|
1528
|
+
}
|
|
1529
|
+
root = {
|
|
1530
|
+
kind: "element",
|
|
1531
|
+
name,
|
|
1532
|
+
open: source.slice(index, end + 1),
|
|
1533
|
+
selfClosing,
|
|
1534
|
+
children: []
|
|
1535
|
+
};
|
|
1536
|
+
children.push(root);
|
|
1537
|
+
} else {
|
|
1538
|
+
const element = {
|
|
1539
|
+
kind: "element",
|
|
1540
|
+
name,
|
|
1541
|
+
open: source.slice(index, end + 1),
|
|
1542
|
+
selfClosing,
|
|
1543
|
+
children: []
|
|
1544
|
+
};
|
|
1545
|
+
currentElement(stack)?.children.push(element);
|
|
1546
|
+
if (!selfClosing) {
|
|
1547
|
+
stack.push(element);
|
|
1548
|
+
}
|
|
1549
|
+
index = end + 1;
|
|
1550
|
+
continue;
|
|
1551
|
+
}
|
|
1552
|
+
if (!selfClosing) {
|
|
1553
|
+
stack.push(root);
|
|
1554
|
+
}
|
|
1555
|
+
index = end + 1;
|
|
1556
|
+
}
|
|
1557
|
+
if (stack.length > 0) {
|
|
1558
|
+
fail(`Unclosed XML element: <${currentElement(stack)?.name}>`);
|
|
1559
|
+
}
|
|
1560
|
+
if (root === void 0) {
|
|
1561
|
+
fail("XML input does not contain a root element");
|
|
1562
|
+
}
|
|
1563
|
+
return { children, root };
|
|
1564
|
+
}
|
|
1565
|
+
function indentation(depth) {
|
|
1566
|
+
return INDENT.repeat(depth);
|
|
1567
|
+
}
|
|
1568
|
+
function renderInline(node) {
|
|
1569
|
+
const content = node.children.map((child) => {
|
|
1570
|
+
if (child.kind === "element") {
|
|
1571
|
+
return renderInline(child);
|
|
1572
|
+
}
|
|
1573
|
+
return child.kind === "text" ? child.value : child.raw;
|
|
1574
|
+
}).join("");
|
|
1575
|
+
return `${node.open}${content}${node.close ?? ""}`;
|
|
1576
|
+
}
|
|
1577
|
+
function hasOnlyTextChildren(node) {
|
|
1578
|
+
return node.children.every((child) => child.kind === "text");
|
|
1579
|
+
}
|
|
1580
|
+
function hasSignificantText(node) {
|
|
1581
|
+
return node.children.some((child) => child.kind === "text" && child.value.trim() !== "");
|
|
1582
|
+
}
|
|
1583
|
+
function formatElement(node, depth, isRoot) {
|
|
1584
|
+
const prefix = indentation(depth);
|
|
1585
|
+
if (node.selfClosing) {
|
|
1586
|
+
return [`${prefix}${node.open}`];
|
|
1587
|
+
}
|
|
1588
|
+
if (node.close === void 0) {
|
|
1589
|
+
fail(`Unclosed XML element: <${node.name}>`);
|
|
1590
|
+
}
|
|
1591
|
+
if (isRoot && hasOnlyTextChildren(node)) {
|
|
1592
|
+
const text = node.children.filter((child) => child.kind === "text").map((child) => child.value).join("");
|
|
1593
|
+
const trimmedText = text.trim();
|
|
1594
|
+
if (trimmedText === "") {
|
|
1595
|
+
return [`${prefix}${node.open}`, `${prefix}${node.close}`];
|
|
1596
|
+
}
|
|
1597
|
+
if (text.includes("\n") || text.includes("\r") || text !== trimmedText) {
|
|
1598
|
+
return [`${prefix}${renderInline(node)}`];
|
|
1599
|
+
}
|
|
1600
|
+
return [`${prefix}${node.open}`, `${indentation(depth + 1)}${trimmedText}`, `${prefix}${node.close}`];
|
|
1601
|
+
}
|
|
1602
|
+
if (hasSignificantText(node)) {
|
|
1603
|
+
return [`${prefix}${renderInline(node)}`];
|
|
1604
|
+
}
|
|
1605
|
+
const lines = [`${prefix}${node.open}`];
|
|
1606
|
+
for (const child of node.children) {
|
|
1607
|
+
if (child.kind === "text") {
|
|
1608
|
+
continue;
|
|
1609
|
+
}
|
|
1610
|
+
if (child.kind === "element") {
|
|
1611
|
+
lines.push(...formatElement(child, depth + 1, false));
|
|
1612
|
+
} else {
|
|
1613
|
+
lines.push(`${indentation(depth + 1)}${child.raw}`);
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
lines.push(`${prefix}${node.close}`);
|
|
1617
|
+
return lines;
|
|
1618
|
+
}
|
|
1619
|
+
function stripTrailingWhitespace(value) {
|
|
1620
|
+
return value.replace(/[ \t]+$/gm, "");
|
|
1621
|
+
}
|
|
1622
|
+
function renderDocument(document2) {
|
|
1623
|
+
const lines = [];
|
|
1624
|
+
for (const child of document2.children) {
|
|
1625
|
+
if (child.kind === "text") {
|
|
1626
|
+
continue;
|
|
1627
|
+
}
|
|
1628
|
+
if (child.kind === "element") {
|
|
1629
|
+
lines.push(...formatElement(child, 0, child === document2.root));
|
|
1630
|
+
} else {
|
|
1631
|
+
lines.push(child.raw);
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
return stripTrailingWhitespace(lines.join("\n")).trim();
|
|
1635
|
+
}
|
|
1636
|
+
function unwrapFormattedFragment(formatted) {
|
|
1637
|
+
const opening = `<${FRAGMENT_ROOT}>`;
|
|
1638
|
+
const closing = `</${FRAGMENT_ROOT}>`;
|
|
1639
|
+
if (!formatted.startsWith(opening) || !formatted.endsWith(closing)) {
|
|
1640
|
+
return void 0;
|
|
1641
|
+
}
|
|
1642
|
+
if (formatted === `${opening}${closing}`) {
|
|
1643
|
+
return "";
|
|
1644
|
+
}
|
|
1645
|
+
const multilineOpening = `${opening}
|
|
1646
|
+
`;
|
|
1647
|
+
const multilineClosing = `
|
|
1648
|
+
${closing}`;
|
|
1649
|
+
if (formatted.startsWith(multilineOpening) && formatted.endsWith(multilineClosing)) {
|
|
1650
|
+
const content = formatted.slice(multilineOpening.length, -multilineClosing.length);
|
|
1651
|
+
return content.split("\n").map((line) => line.startsWith(INDENT) ? line.slice(INDENT.length) : line).join("\n");
|
|
1652
|
+
}
|
|
1653
|
+
return formatted.slice(opening.length, -closing.length);
|
|
1654
|
+
}
|
|
1655
|
+
function formatXmlFragment(xml) {
|
|
1656
|
+
const source = xml.trim();
|
|
1657
|
+
if (source === "") {
|
|
1658
|
+
return "";
|
|
1659
|
+
}
|
|
1660
|
+
const wrapped = `<${FRAGMENT_ROOT}>${source}</${FRAGMENT_ROOT}>`;
|
|
1661
|
+
let formatted;
|
|
1662
|
+
try {
|
|
1663
|
+
formatted = renderDocument(parseXml(wrapped));
|
|
1664
|
+
} catch {
|
|
1665
|
+
return xml;
|
|
1666
|
+
}
|
|
1667
|
+
return unwrapFormattedFragment(formatted) ?? xml;
|
|
1668
|
+
}
|
|
1669
|
+
|
|
1670
|
+
// packages/ssml-editor-react/src/locales.ts
|
|
1671
|
+
var EDITOR_COPY = {
|
|
1672
|
+
ja: {
|
|
1673
|
+
editorAriaLabel: "SSML\u30A8\u30C7\u30A3\u30BF\u30FC",
|
|
1674
|
+
toolbarAriaLabel: "SSML\u30C4\u30FC\u30EB\u30D0\u30FC",
|
|
1675
|
+
clearAll: "\u5168\u3066\u30AF\u30EA\u30A2",
|
|
1676
|
+
clearAllTitle: "\u97F3\u58F0\u8A2D\u5B9A\u3092\u4FDD\u6301\u3057\u3066XML\u8981\u7D20\u3092\u524A\u9664\u3057\u672C\u6587\u3092\u6B8B\u3059",
|
|
1677
|
+
undo: "\u5143\u306B\u623B\u3059",
|
|
1678
|
+
undoTitle: "\u76F4\u524D\u306E\u5909\u66F4\u3092\u5143\u306B\u623B\u3059",
|
|
1679
|
+
redo: "\u3084\u308A\u76F4\u3059",
|
|
1680
|
+
redoTitle: "\u5143\u306B\u623B\u3057\u305F\u5909\u66F4\u3092\u3084\u308A\u76F4\u3059",
|
|
1681
|
+
help: "\u8AAC\u660E",
|
|
1682
|
+
helpTitle: "\u30DC\u30BF\u30F3\u3068\u30D1\u30E9\u30E1\u30FC\u30BF\u306E\u8AAC\u660E\u3092\u8868\u793A",
|
|
1683
|
+
helpHeading: "\u30DC\u30BF\u30F3\u3068\u30D1\u30E9\u30E1\u30FC\u30BF\u306E\u8AAC\u660E",
|
|
1684
|
+
helpDescription: "\u5404\u30B3\u30F3\u30C8\u30ED\u30FC\u30EB\u306E\u6A5F\u80FD\u3068\u30D1\u30E9\u30E1\u30FC\u30BF\u3092\u78BA\u8A8D\u3067\u304D\u307E\u3059\u3002",
|
|
1685
|
+
parameters: "\u30D1\u30E9\u30E1\u30FC\u30BF",
|
|
1686
|
+
format: "\u30D5\u30A9\u30FC\u30DE\u30C3\u30C8",
|
|
1687
|
+
formatTitle: "\u672C\u6587\u306EXML\u3092\u6539\u884C\u3057\u3066\u898B\u3084\u3059\u304F\u8868\u793A",
|
|
1688
|
+
decorations: "\u88C5\u98FE",
|
|
1689
|
+
decorationsShowTitle: "\u30A4\u30F3\u30E9\u30A4\u30F3\u88C5\u98FE\u3092\u8868\u793A",
|
|
1690
|
+
decorationsHideTitle: "\u30A4\u30F3\u30E9\u30A4\u30F3\u88C5\u98FE\u3092\u975E\u8868\u793A",
|
|
1691
|
+
syntaxError: "\u69CB\u6587\u30A8\u30E9\u30FC",
|
|
1692
|
+
selectionActions: "\u9078\u629E\u7BC4\u56F2\u306E\u64CD\u4F5C",
|
|
1693
|
+
selectionCountSuffix: "\u6587\u5B57",
|
|
1694
|
+
previewSelection: "\u9078\u629E\u90E8\u5206\u3092\u8A66\u8074",
|
|
1695
|
+
previewSelectionTitle: "\u9078\u629E\u90E8\u5206\u306ESSML\u3092\u8A66\u8074"
|
|
1696
|
+
},
|
|
1697
|
+
en: {
|
|
1698
|
+
editorAriaLabel: "SSML editor",
|
|
1699
|
+
toolbarAriaLabel: "SSML toolbar",
|
|
1700
|
+
clearAll: "Clear all",
|
|
1701
|
+
clearAllTitle: "Remove non-voice XML elements and keep the text and voice settings",
|
|
1702
|
+
undo: "Undo",
|
|
1703
|
+
undoTitle: "Undo the last change",
|
|
1704
|
+
redo: "Redo",
|
|
1705
|
+
redoTitle: "Redo the last undone change",
|
|
1706
|
+
help: "Help",
|
|
1707
|
+
helpTitle: "Show button and parameter descriptions",
|
|
1708
|
+
helpHeading: "Button and parameter descriptions",
|
|
1709
|
+
helpDescription: "Review what each control does and its parameters.",
|
|
1710
|
+
parameters: "Parameters",
|
|
1711
|
+
format: "Format",
|
|
1712
|
+
formatTitle: "Format the XML in the editor",
|
|
1713
|
+
decorations: "Decorations",
|
|
1714
|
+
decorationsShowTitle: "Show inline decorations",
|
|
1715
|
+
decorationsHideTitle: "Hide inline decorations",
|
|
1716
|
+
syntaxError: "Syntax error",
|
|
1717
|
+
selectionActions: "Selection actions",
|
|
1718
|
+
selectionCountSuffix: " characters",
|
|
1719
|
+
previewSelection: "Preview selection",
|
|
1720
|
+
previewSelectionTitle: "Preview the selected SSML"
|
|
1721
|
+
}
|
|
1722
|
+
};
|
|
1723
|
+
var INLINE_BADGE_COPY = {
|
|
1724
|
+
ja: {
|
|
1725
|
+
pause: "\u9593",
|
|
1726
|
+
pitch: "\u30D4\u30C3\u30C1\u5909\u5316",
|
|
1727
|
+
prosody: "\u58F0\u306E\u8ABF\u6574"
|
|
1728
|
+
},
|
|
1729
|
+
en: {
|
|
1730
|
+
pause: "Pause",
|
|
1731
|
+
pitch: "Pitch change",
|
|
1732
|
+
prosody: "Prosody"
|
|
1733
|
+
}
|
|
1734
|
+
};
|
|
1735
|
+
var SSML_HOVER_COPY = {
|
|
1736
|
+
ja: {
|
|
1737
|
+
parameterHeading: "\u30D1\u30E9\u30E1\u30FC\u30BF",
|
|
1738
|
+
parametersHeading: "\u30D1\u30E9\u30E1\u30FC\u30BF",
|
|
1739
|
+
allowedValues: "\u4F7F\u7528\u3067\u304D\u308B\u5024",
|
|
1740
|
+
example: "\u4F8B",
|
|
1741
|
+
noParameters: "\u3053\u306E\u8981\u7D20\u306B\u30D1\u30E9\u30E1\u30FC\u30BF\u306F\u3042\u308A\u307E\u305B\u3093\u3002",
|
|
1742
|
+
tags: {
|
|
1743
|
+
voice: {
|
|
1744
|
+
title: "\u97F3\u58F0",
|
|
1745
|
+
description: "\u56F2\u307E\u308C\u305F\u30C6\u30AD\u30B9\u30C8\u306E\u5408\u6210\u306B\u4F7F\u7528\u3059\u308B\u97F3\u58F0\u3068\u3001\u4EFB\u610F\u306E\u97F3\u58F0\u52B9\u679C\u3092\u9078\u629E\u3057\u307E\u3059\u3002",
|
|
1746
|
+
parameters: {
|
|
1747
|
+
name: { title: "name", description: "\u97F3\u58F0\u540D\u3002\u4F8B: `en-US-JennyNeural`\u3002" },
|
|
1748
|
+
effect: { title: "effect", description: "\u4EFB\u610F\u306E\u97F3\u58F0\u52B9\u679C\u3002\u4F8B: `eq_car`\u3002" }
|
|
1749
|
+
}
|
|
1750
|
+
},
|
|
1751
|
+
prosody: {
|
|
1752
|
+
title: "\u97FB\u5F8B",
|
|
1753
|
+
description: "\u56F2\u307E\u308C\u305F\u30C6\u30AD\u30B9\u30C8\u306E\u901F\u5EA6\u3001\u30D4\u30C3\u30C1\u3001\u97F3\u91CF\u3001\u307E\u305F\u306F\u30D4\u30C3\u30C1\u66F2\u7DDA\u3092\u5909\u66F4\u3057\u307E\u3059\u3002",
|
|
1754
|
+
parameters: {
|
|
1755
|
+
rate: { title: "rate", description: "\u767A\u8A71\u901F\u5EA6\u3092\u6307\u5B9A\u3057\u307E\u3059\u3002" },
|
|
1756
|
+
pitch: { title: "pitch", description: "\u540D\u524D\u4ED8\u304D\u306E\u5024\u3001\u5272\u5408\u3001\u5468\u6CE2\u6570\u3001\u307E\u305F\u306F\u534A\u97F3\u3067\u30D4\u30C3\u30C1\u3092\u8ABF\u6574\u3057\u307E\u3059\u3002" },
|
|
1757
|
+
volume: { title: "volume", description: "\u540D\u524D\u4ED8\u304D\u306E\u5024\u3001\u5272\u5408\u3001\u307E\u305F\u306F\u30C7\u30B7\u30D9\u30EB\u5024\u3067\u97F3\u91CF\u3092\u6307\u5B9A\u3057\u307E\u3059\u3002" },
|
|
1758
|
+
contour: { title: "contour", description: "\u30C6\u30AD\u30B9\u30C8\u5185\u306E\u4F4D\u7F6E\u3054\u3068\u306E\u76F8\u5BFE\u7684\u306A\u30D4\u30C3\u30C1\u5909\u5316\u3092\u5B9A\u7FA9\u3057\u307E\u3059\u3002" },
|
|
1759
|
+
range: { title: "range", description: "\u97F3\u58F0\u306E\u30D4\u30C3\u30C1\u7BC4\u56F2\u3092\u8ABF\u6574\u3057\u307E\u3059\u3002" }
|
|
1760
|
+
}
|
|
1761
|
+
},
|
|
1762
|
+
break: {
|
|
1763
|
+
title: "\u9593",
|
|
1764
|
+
description: "\u5358\u8A9E\u3084\u305D\u306E\u4ED6\u306E\u97F3\u58F0\u30B3\u30F3\u30C6\u30F3\u30C4\u306E\u9593\u306B\u30DD\u30FC\u30BA\u3092\u633F\u5165\u3057\u307E\u3059\u3002",
|
|
1765
|
+
parameters: {
|
|
1766
|
+
time: { title: "time", description: "\u30DD\u30FC\u30BA\u306E\u9577\u3055\u3002\u4F8B: `500ms` \u307E\u305F\u306F `1s`\u3002" },
|
|
1767
|
+
strength: { title: "strength", description: "\u76F8\u5BFE\u7684\u306A\u30DD\u30FC\u30BA\u306E\u5F37\u3055\u3002" }
|
|
1768
|
+
}
|
|
1769
|
+
},
|
|
1770
|
+
"mstts:express-as": {
|
|
1771
|
+
title: "\u8868\u73FE",
|
|
1772
|
+
description: "\u56F2\u307E\u308C\u305F\u30C6\u30AD\u30B9\u30C8\u306B\u97F3\u58F0\u30B9\u30BF\u30A4\u30EB\u3001\u30B9\u30BF\u30A4\u30EB\u306E\u5F37\u3055\u3001\u307E\u305F\u306F\u5F79\u5272\u3092\u9069\u7528\u3057\u307E\u3059\u3002",
|
|
1773
|
+
parameters: {
|
|
1774
|
+
style: { title: "style", description: "\u9078\u629E\u3057\u305F\u97F3\u58F0\u304C\u5BFE\u5FDC\u3059\u308B\u97F3\u58F0\u30B9\u30BF\u30A4\u30EB\u3002\u4F8B: `cheerful`\u3002" },
|
|
1775
|
+
styledegree: { title: "styledegree", description: "\u9078\u629E\u3057\u305F\u97F3\u58F0\u30B9\u30BF\u30A4\u30EB\u306E\u5F37\u3055\u3092\u6307\u5B9A\u3057\u307E\u3059\u3002" },
|
|
1776
|
+
role: { title: "role", description: "\u5BFE\u5FDC\u3057\u3066\u3044\u308B\u5834\u5408\u306B\u97F3\u58F0\u306E\u5F79\u5272\u3092\u5909\u66F4\u3057\u307E\u3059\u3002" }
|
|
1777
|
+
}
|
|
1778
|
+
},
|
|
1779
|
+
"say-as": {
|
|
1780
|
+
title: "\u8AAD\u307F\u4E0A\u3052\u65B9",
|
|
1781
|
+
description: "\u56F2\u307E\u308C\u305F\u30C6\u30AD\u30B9\u30C8\u306E\u89E3\u91C8\u65B9\u6CD5\u3068\u8AAD\u307F\u4E0A\u3052\u65B9\u3092\u6307\u5B9A\u3057\u307E\u3059\u3002",
|
|
1782
|
+
parameters: {
|
|
1783
|
+
"interpret-as": { title: "interpret-as", description: "\u6587\u5B57\u3001\u6570\u5B57\u3001\u65E5\u4ED8\u3001\u6642\u523B\u306A\u3069\u306E\u89E3\u91C8\u3092\u6307\u5B9A\u3057\u307E\u3059\u3002" },
|
|
1784
|
+
format: { title: "format", description: "\u9078\u629E\u3057\u305F\u89E3\u91C8\u306E\u5F62\u5F0F\u3092\u88DC\u8DB3\u3057\u307E\u3059\u3002" },
|
|
1785
|
+
detail: { title: "detail", description: "\u9078\u629E\u3057\u305F\u89E3\u91C8\u306E\u8A73\u7D30\u3092\u88DC\u8DB3\u3057\u307E\u3059\u3002" }
|
|
1786
|
+
}
|
|
1787
|
+
},
|
|
1788
|
+
phoneme: {
|
|
1789
|
+
title: "\u97F3\u7D20",
|
|
1790
|
+
description: "\u6307\u5B9A\u3057\u305F\u97F3\u7D20\u8868\u8A18\u3067\u901A\u5E38\u306E\u767A\u97F3\u3092\u7F6E\u304D\u63DB\u3048\u307E\u3059\u3002",
|
|
1791
|
+
parameters: {
|
|
1792
|
+
alphabet: { title: "alphabet", description: "`ph` \u5024\u306B\u4F7F\u7528\u3059\u308B\u97F3\u7D20\u30A2\u30EB\u30D5\u30A1\u30D9\u30C3\u30C8\u3002" },
|
|
1793
|
+
ph: { title: "ph", description: "\u56F2\u307E\u308C\u305F\u30C6\u30AD\u30B9\u30C8\u306E\u97F3\u7D20\u8868\u8A18\u3002" }
|
|
1794
|
+
}
|
|
1795
|
+
},
|
|
1796
|
+
emphasis: {
|
|
1797
|
+
title: "\u5F37\u8ABF",
|
|
1798
|
+
description: "\u56F2\u307E\u308C\u305F\u30C6\u30AD\u30B9\u30C8\u3092\u5F37\u8ABF\u3057\u307E\u3059\u3002",
|
|
1799
|
+
parameters: {
|
|
1800
|
+
level: { title: "level", description: "\u5F37\u8ABF\u306E\u5EA6\u5408\u3044\u3092\u6307\u5B9A\u3057\u307E\u3059\u3002" }
|
|
1801
|
+
}
|
|
1802
|
+
},
|
|
1803
|
+
audio: {
|
|
1804
|
+
title: "\u97F3\u58F0\u30D5\u30A1\u30A4\u30EB",
|
|
1805
|
+
description: "\u5408\u6210\u7D50\u679C\u306E\u4E00\u90E8\u3068\u3057\u3066\u97F3\u58F0\u30D5\u30A1\u30A4\u30EB\u3092\u518D\u751F\u3057\u307E\u3059\u3002",
|
|
1806
|
+
parameters: {
|
|
1807
|
+
src: { title: "src", description: "\u97F3\u58F0\u30D5\u30A1\u30A4\u30EB\u306E URI\u3002" },
|
|
1808
|
+
desc: { title: "desc", description: "\u97F3\u58F0\u3092\u518D\u751F\u3067\u304D\u306A\u3044\u5834\u5408\u306B\u4F7F\u7528\u3059\u308B\u4EE3\u66FF\u30C6\u30AD\u30B9\u30C8\u3002" },
|
|
1809
|
+
clipBegin: { title: "clipBegin", description: "\u97F3\u58F0\u30D5\u30A1\u30A4\u30EB\u5185\u306E\u958B\u59CB\u4F4D\u7F6E\u3002\u4F8B: `0s`\u3002" },
|
|
1810
|
+
clipEnd: { title: "clipEnd", description: "\u97F3\u58F0\u30D5\u30A1\u30A4\u30EB\u5185\u306E\u7D42\u4E86\u4F4D\u7F6E\u3002\u4F8B: `5s`\u3002" },
|
|
1811
|
+
speed: { title: "speed", description: "\u97F3\u58F0\u30D5\u30A1\u30A4\u30EB\u306E\u518D\u751F\u901F\u5EA6\u3002\u4F8B: `1.0`\u3002" },
|
|
1812
|
+
repeatCount: { title: "repeatCount", description: "\u97F3\u58F0\u3092\u7E70\u308A\u8FD4\u3059\u56DE\u6570\u3002\u4F8B: `2`\u3002" },
|
|
1813
|
+
repeatDuration: { title: "repeatDuration", description: "\u97F3\u58F0\u3092\u7E70\u308A\u8FD4\u3059\u5408\u8A08\u6642\u9593\u3002\u4F8B: `10s`\u3002" },
|
|
1814
|
+
soundLevel: { title: "soundLevel", description: "\u30C7\u30B7\u30D9\u30EB\u5358\u4F4D\u306E\u97F3\u91CF\u8ABF\u6574\u3002\u4F8B: `-3dB`\u3002" }
|
|
1815
|
+
}
|
|
1816
|
+
},
|
|
1817
|
+
sub: {
|
|
1818
|
+
title: "\u7F6E\u63DB",
|
|
1819
|
+
description: "\u56F2\u307E\u308C\u305F\u30C6\u30AD\u30B9\u30C8\u306E\u4EE3\u308F\u308A\u306B\u5225\u540D\u30C6\u30AD\u30B9\u30C8\u3092\u8AAD\u307F\u4E0A\u3052\u307E\u3059\u3002",
|
|
1820
|
+
parameters: {
|
|
1821
|
+
alias: { title: "alias", description: "\u5143\u306E\u30C6\u30AD\u30B9\u30C8\u306E\u4EE3\u308F\u308A\u306B\u8AAD\u307F\u4E0A\u3052\u308B\u30C6\u30AD\u30B9\u30C8\u3002\u4F8B: `World Wide Web`\u3002" }
|
|
1822
|
+
}
|
|
1823
|
+
},
|
|
1824
|
+
lang: {
|
|
1825
|
+
title: "\u8A00\u8A9E",
|
|
1826
|
+
description: "\u56F2\u307E\u308C\u305F\u30C6\u30AD\u30B9\u30C8\u306E\u8AAD\u307F\u4E0A\u3052\u8A00\u8A9E\u3092\u5909\u66F4\u3057\u307E\u3059\u3002",
|
|
1827
|
+
parameters: {
|
|
1828
|
+
"xml:lang": { title: "xml:lang", description: "BCP-47 \u8A00\u8A9E\u30BF\u30B0\u3002\u4F8B: `ja-JP`\u3002" }
|
|
1829
|
+
}
|
|
1830
|
+
},
|
|
1831
|
+
mark: {
|
|
1832
|
+
title: "\u30DE\u30FC\u30AB\u30FC",
|
|
1833
|
+
description: "\u5408\u6210\u97F3\u58F0\u30B9\u30C8\u30EA\u30FC\u30E0\u306B\u30AB\u30B9\u30BF\u30E0\u30DE\u30FC\u30AB\u30FC\u3092\u633F\u5165\u3057\u307E\u3059\u3002",
|
|
1834
|
+
parameters: {
|
|
1835
|
+
name: { title: "name", description: "\u30A2\u30D7\u30EA\u30B1\u30FC\u30B7\u30E7\u30F3\u3067\u5B9A\u7FA9\u3057\u305F\u30DE\u30FC\u30AB\u30FC\u540D\u3002\u4F8B: `chapter-1`\u3002" }
|
|
1836
|
+
}
|
|
1837
|
+
},
|
|
1838
|
+
bookmark: {
|
|
1839
|
+
title: "\u30D6\u30C3\u30AF\u30DE\u30FC\u30AF",
|
|
1840
|
+
description: "\u5408\u6210\u97F3\u58F0\u30B9\u30C8\u30EA\u30FC\u30E0\u306B\u30D6\u30C3\u30AF\u30DE\u30FC\u30AF\u30DE\u30FC\u30AB\u30FC\u3092\u633F\u5165\u3057\u307E\u3059\u3002",
|
|
1841
|
+
parameters: {
|
|
1842
|
+
mark: { title: "mark", description: "\u30A2\u30D7\u30EA\u30B1\u30FC\u30B7\u30E7\u30F3\u3067\u5B9A\u7FA9\u3057\u305F\u30D6\u30C3\u30AF\u30DE\u30FC\u30AF\u540D\u3002\u4F8B: `chapter-1`\u3002" }
|
|
1843
|
+
}
|
|
1844
|
+
},
|
|
1845
|
+
lexicon: {
|
|
1846
|
+
title: "\u767A\u97F3\u8F9E\u66F8",
|
|
1847
|
+
description: "\u5408\u6210\u6587\u66F8\u306B\u767A\u97F3\u8F9E\u66F8\u3092\u95A2\u9023\u4ED8\u3051\u307E\u3059\u3002",
|
|
1848
|
+
parameters: {
|
|
1849
|
+
uri: { title: "uri", description: "\u767A\u97F3\u8F9E\u66F8\u306E URI\u3002" }
|
|
1850
|
+
}
|
|
1851
|
+
},
|
|
1852
|
+
p: { title: "\u6BB5\u843D", description: "\u30C6\u30AD\u30B9\u30C8\u3092\u6BB5\u843D\u3068\u3057\u3066\u307E\u3068\u3081\u307E\u3059\u3002", parameters: {} },
|
|
1853
|
+
s: { title: "\u6587", description: "\u30C6\u30AD\u30B9\u30C8\u3092\u6587\u3068\u3057\u3066\u307E\u3068\u3081\u307E\u3059\u3002", parameters: {} },
|
|
1854
|
+
w: { title: "\u5358\u8A9E", description: "\u30C6\u30AD\u30B9\u30C8\u3092\u5358\u8A9E\u3068\u3057\u3066\u307E\u3068\u3081\u307E\u3059\u3002", parameters: {} },
|
|
1855
|
+
"mstts:silence": {
|
|
1856
|
+
title: "\u7121\u97F3",
|
|
1857
|
+
description: "\u30C6\u30AD\u30B9\u30C8\u306E\u524D\u5F8C\u3001\u307E\u305F\u306F\u53E5\u8AAD\u70B9\u306E\u5883\u754C\u306B\u6307\u5B9A\u3057\u305F\u7121\u97F3\u3092\u8FFD\u52A0\u3057\u307E\u3059\u3002",
|
|
1858
|
+
parameters: {
|
|
1859
|
+
type: { title: "type", description: "\u7121\u97F3\u306E\u4F4D\u7F6E\u307E\u305F\u306F\u53E5\u8AAD\u70B9\u306E\u5883\u754C\u3002" },
|
|
1860
|
+
value: { title: "value", description: "\u7121\u97F3\u306E\u9577\u3055\u3002\u4F8B: `300ms`\u3002" }
|
|
1861
|
+
}
|
|
1862
|
+
},
|
|
1863
|
+
"mstts:viseme": {
|
|
1864
|
+
title: "\u30D3\u30BC\u30FC\u30E0",
|
|
1865
|
+
description: "\u5408\u6210\u97F3\u58F0\u306E\u30D3\u30BC\u30FC\u30E0\u30A4\u30D9\u30F3\u30C8\u3092\u8981\u6C42\u3057\u307E\u3059\u3002",
|
|
1866
|
+
parameters: {
|
|
1867
|
+
type: { title: "type", description: "\u30D3\u30BC\u30FC\u30E0\u30A4\u30D9\u30F3\u30C8\u306E\u5F62\u5F0F\u3002" }
|
|
1868
|
+
}
|
|
1869
|
+
}
|
|
1870
|
+
}
|
|
1871
|
+
},
|
|
1872
|
+
en: {
|
|
1873
|
+
parameterHeading: "Parameter",
|
|
1874
|
+
parametersHeading: "Parameters",
|
|
1875
|
+
allowedValues: "Allowed values",
|
|
1876
|
+
example: "Example",
|
|
1877
|
+
noParameters: "This element has no parameters.",
|
|
1878
|
+
tags: {
|
|
1879
|
+
voice: {
|
|
1880
|
+
title: "Voice",
|
|
1881
|
+
description: "Selects the voice and optional voice effect used to synthesize the enclosed text.",
|
|
1882
|
+
parameters: {
|
|
1883
|
+
name: { title: "name", description: "The voice name, such as `en-US-JennyNeural`." },
|
|
1884
|
+
effect: { title: "effect", description: "An optional voice effect, such as `eq_car`." }
|
|
1885
|
+
}
|
|
1886
|
+
},
|
|
1887
|
+
prosody: {
|
|
1888
|
+
title: "Prosody",
|
|
1889
|
+
description: "Changes the speaking rate, pitch, volume, or pitch contour of the enclosed text.",
|
|
1890
|
+
parameters: {
|
|
1891
|
+
rate: { title: "rate", description: "Controls speaking speed." },
|
|
1892
|
+
pitch: {
|
|
1893
|
+
title: "pitch",
|
|
1894
|
+
description: "Adjusts pitch using a named value, percentage, frequency, or semitone value."
|
|
1895
|
+
},
|
|
1896
|
+
volume: {
|
|
1897
|
+
title: "volume",
|
|
1898
|
+
description: "Controls loudness using a named value, percentage, or decibel value."
|
|
1899
|
+
},
|
|
1900
|
+
contour: {
|
|
1901
|
+
title: "contour",
|
|
1902
|
+
description: "Defines a sequence of relative pitch changes at positions in the text."
|
|
1903
|
+
},
|
|
1904
|
+
range: { title: "range", description: "Adjusts the pitch range of the voice." }
|
|
1905
|
+
}
|
|
1906
|
+
},
|
|
1907
|
+
break: {
|
|
1908
|
+
title: "Break",
|
|
1909
|
+
description: "Inserts a pause between words or other spoken content.",
|
|
1910
|
+
parameters: {
|
|
1911
|
+
time: { title: "time", description: "The pause duration, for example `500ms` or `1s`." },
|
|
1912
|
+
strength: { title: "strength", description: "The relative pause strength." }
|
|
1913
|
+
}
|
|
1914
|
+
},
|
|
1915
|
+
"mstts:express-as": {
|
|
1916
|
+
title: "Express-as",
|
|
1917
|
+
description: "Applies a speaking style, style degree, or role to the enclosed text.",
|
|
1918
|
+
parameters: {
|
|
1919
|
+
style: {
|
|
1920
|
+
title: "style",
|
|
1921
|
+
description: "The speaking style supported by the selected voice, such as `cheerful`."
|
|
1922
|
+
},
|
|
1923
|
+
styledegree: { title: "styledegree", description: "Controls the intensity of the selected speaking style." },
|
|
1924
|
+
role: { title: "role", description: "Changes the speaking role when supported by the selected voice." }
|
|
1925
|
+
}
|
|
1926
|
+
},
|
|
1927
|
+
"say-as": {
|
|
1928
|
+
title: "Say-as",
|
|
1929
|
+
description: "Controls how the enclosed text is interpreted and spoken.",
|
|
1930
|
+
parameters: {
|
|
1931
|
+
"interpret-as": {
|
|
1932
|
+
title: "interpret-as",
|
|
1933
|
+
description: "Specifies the interpretation, such as characters, digits, date, or time."
|
|
1934
|
+
},
|
|
1935
|
+
format: { title: "format", description: "Provides a format hint for the selected interpretation." },
|
|
1936
|
+
detail: {
|
|
1937
|
+
title: "detail",
|
|
1938
|
+
description: "Provides an additional detail hint for the selected interpretation."
|
|
1939
|
+
}
|
|
1940
|
+
}
|
|
1941
|
+
},
|
|
1942
|
+
phoneme: {
|
|
1943
|
+
title: "Phoneme",
|
|
1944
|
+
description: "Replaces normal pronunciation with the supplied phonetic pronunciation.",
|
|
1945
|
+
parameters: {
|
|
1946
|
+
alphabet: { title: "alphabet", description: "The phonetic alphabet used by the `ph` value." },
|
|
1947
|
+
ph: { title: "ph", description: "The phonetic pronunciation for the enclosed text." }
|
|
1948
|
+
}
|
|
1949
|
+
},
|
|
1950
|
+
emphasis: {
|
|
1951
|
+
title: "Emphasis",
|
|
1952
|
+
description: "Adds emphasis to the enclosed text.",
|
|
1953
|
+
parameters: {
|
|
1954
|
+
level: { title: "level", description: "Controls the amount of emphasis." }
|
|
1955
|
+
}
|
|
1956
|
+
},
|
|
1957
|
+
audio: {
|
|
1958
|
+
title: "Audio",
|
|
1959
|
+
description: "Plays an audio file as part of the synthesized output.",
|
|
1960
|
+
parameters: {
|
|
1961
|
+
src: { title: "src", description: "The URI of the audio file." },
|
|
1962
|
+
desc: { title: "desc", description: "Alternative text to use if the audio cannot be played." },
|
|
1963
|
+
clipBegin: { title: "clipBegin", description: "The starting offset within the audio file." },
|
|
1964
|
+
clipEnd: { title: "clipEnd", description: "The ending offset within the audio file." },
|
|
1965
|
+
speed: { title: "speed", description: "The playback speed of the audio file." },
|
|
1966
|
+
repeatCount: { title: "repeatCount", description: "The number of times to repeat the audio." },
|
|
1967
|
+
repeatDuration: {
|
|
1968
|
+
title: "repeatDuration",
|
|
1969
|
+
description: "The total duration for which the audio may repeat."
|
|
1970
|
+
},
|
|
1971
|
+
soundLevel: { title: "soundLevel", description: "The audio volume adjustment in decibels." }
|
|
1972
|
+
}
|
|
1973
|
+
},
|
|
1974
|
+
sub: {
|
|
1975
|
+
title: "Substitution",
|
|
1976
|
+
description: "Substitutes the alias text when speaking the enclosed text.",
|
|
1977
|
+
parameters: {
|
|
1978
|
+
alias: { title: "alias", description: "The text to speak instead of the enclosed text." }
|
|
1979
|
+
}
|
|
1980
|
+
},
|
|
1981
|
+
lang: {
|
|
1982
|
+
title: "Language",
|
|
1983
|
+
description: "Changes the language used for the enclosed text.",
|
|
1984
|
+
parameters: {
|
|
1985
|
+
"xml:lang": { title: "xml:lang", description: "The BCP-47 language tag." }
|
|
1986
|
+
}
|
|
1987
|
+
},
|
|
1988
|
+
mark: {
|
|
1989
|
+
title: "Mark",
|
|
1990
|
+
description: "Inserts a custom marker into the synthesized audio stream.",
|
|
1991
|
+
parameters: {
|
|
1992
|
+
name: { title: "name", description: "The application-defined marker name." }
|
|
1993
|
+
}
|
|
1994
|
+
},
|
|
1995
|
+
bookmark: {
|
|
1996
|
+
title: "Bookmark",
|
|
1997
|
+
description: "Inserts a bookmark marker into the synthesized audio stream.",
|
|
1998
|
+
parameters: {
|
|
1999
|
+
mark: { title: "mark", description: "The application-defined bookmark name." }
|
|
2000
|
+
}
|
|
2001
|
+
},
|
|
2002
|
+
lexicon: {
|
|
2003
|
+
title: "Lexicon",
|
|
2004
|
+
description: "Associates a pronunciation lexicon with the synthesized document.",
|
|
2005
|
+
parameters: {
|
|
2006
|
+
uri: { title: "uri", description: "The URI of the pronunciation lexicon." }
|
|
2007
|
+
}
|
|
2008
|
+
},
|
|
2009
|
+
p: { title: "Paragraph", description: "Groups text into a paragraph.", parameters: {} },
|
|
2010
|
+
s: { title: "Sentence", description: "Groups text into a sentence.", parameters: {} },
|
|
2011
|
+
w: { title: "Word", description: "Groups text into a word.", parameters: {} },
|
|
2012
|
+
"mstts:silence": {
|
|
2013
|
+
title: "Silence",
|
|
2014
|
+
description: "Adds a specified silence before or after text or at a punctuation boundary.",
|
|
2015
|
+
parameters: {
|
|
2016
|
+
type: { title: "type", description: "The silence position or punctuation boundary." },
|
|
2017
|
+
value: { title: "value", description: "The silence duration, for example `300ms`." }
|
|
2018
|
+
}
|
|
2019
|
+
},
|
|
2020
|
+
"mstts:viseme": {
|
|
2021
|
+
title: "Viseme",
|
|
2022
|
+
description: "Requests viseme events for the synthesized audio.",
|
|
2023
|
+
parameters: {
|
|
2024
|
+
type: { title: "type", description: "The viseme event format." }
|
|
2025
|
+
}
|
|
2026
|
+
}
|
|
2027
|
+
}
|
|
2028
|
+
}
|
|
2029
|
+
};
|
|
2030
|
+
|
|
2031
|
+
// packages/ssml-editor-react/src/ssmlHover.ts
|
|
2032
|
+
var {
|
|
2033
|
+
BREAK_STRENGTH_PRESETS: BREAK_STRENGTH_PRESETS2,
|
|
2034
|
+
EMPHASIS_LEVEL_PRESETS: EMPHASIS_LEVEL_PRESETS2,
|
|
2035
|
+
PHONEME_ALPHABET_PRESETS: PHONEME_ALPHABET_PRESETS2,
|
|
2036
|
+
PROSODY_RATE_VALUES: PROSODY_RATE_VALUES2,
|
|
2037
|
+
PROSODY_VOLUME_PRESETS: PROSODY_VOLUME_PRESETS2,
|
|
2038
|
+
SILENCE_TYPE_PRESETS: SILENCE_TYPE_PRESETS2,
|
|
2039
|
+
SSML_PRESET_EXAMPLES: SSML_PRESET_EXAMPLES2,
|
|
2040
|
+
VISEME_TYPE_PRESETS: VISEME_TYPE_PRESETS2
|
|
2041
|
+
} = ssmlPresets_exports;
|
|
2042
|
+
var SSML_TAG_DEFINITIONS = [
|
|
2043
|
+
{
|
|
2044
|
+
name: "voice",
|
|
2045
|
+
description: "Selects the voice and optional voice effect used to synthesize the enclosed text.",
|
|
2046
|
+
parameters: [
|
|
2047
|
+
{
|
|
2048
|
+
name: "name",
|
|
2049
|
+
description: "The voice name, such as `en-US-JennyNeural`.",
|
|
2050
|
+
example: "en-US-JennyNeural"
|
|
2051
|
+
},
|
|
2052
|
+
{
|
|
2053
|
+
name: "effect",
|
|
2054
|
+
description: "An optional voice effect, such as `eq_car`."
|
|
2055
|
+
}
|
|
2056
|
+
]
|
|
2057
|
+
},
|
|
2058
|
+
{
|
|
2059
|
+
name: "prosody",
|
|
2060
|
+
description: "Changes the speaking rate, pitch, volume, or pitch contour of the enclosed text.",
|
|
2061
|
+
parameters: [
|
|
2062
|
+
{
|
|
2063
|
+
name: "rate",
|
|
2064
|
+
description: "Controls speaking speed.",
|
|
2065
|
+
values: PROSODY_RATE_VALUES2,
|
|
2066
|
+
example: SSML_PRESET_EXAMPLES2.prosodyRate
|
|
2067
|
+
},
|
|
2068
|
+
{
|
|
2069
|
+
name: "pitch",
|
|
2070
|
+
description: "Adjusts pitch using a named value, percentage, frequency, or semitone value.",
|
|
2071
|
+
example: SSML_PRESET_EXAMPLES2.prosodyPitch
|
|
2072
|
+
},
|
|
2073
|
+
{
|
|
2074
|
+
name: "volume",
|
|
2075
|
+
description: "Controls loudness using a named value, percentage, or decibel value.",
|
|
2076
|
+
values: PROSODY_VOLUME_PRESETS2,
|
|
2077
|
+
example: SSML_PRESET_EXAMPLES2.prosodyVolume
|
|
2078
|
+
},
|
|
2079
|
+
{
|
|
2080
|
+
name: "contour",
|
|
2081
|
+
description: "Defines a sequence of relative pitch changes at positions in the text.",
|
|
2082
|
+
example: "(0%,+0st) (100%,+2st)"
|
|
2083
|
+
},
|
|
2084
|
+
{
|
|
2085
|
+
name: "range",
|
|
2086
|
+
description: "Adjusts the pitch range of the voice.",
|
|
2087
|
+
example: "+2st"
|
|
2088
|
+
}
|
|
2089
|
+
]
|
|
2090
|
+
},
|
|
2091
|
+
{
|
|
2092
|
+
name: "break",
|
|
2093
|
+
description: "Inserts a pause between words or other spoken content.",
|
|
2094
|
+
parameters: [
|
|
2095
|
+
{
|
|
2096
|
+
name: "time",
|
|
2097
|
+
description: "The pause duration, for example `500ms` or `1s`.",
|
|
2098
|
+
example: SSML_PRESET_EXAMPLES2.breakTime
|
|
2099
|
+
},
|
|
2100
|
+
{
|
|
2101
|
+
name: "strength",
|
|
2102
|
+
description: "The relative pause strength.",
|
|
2103
|
+
values: BREAK_STRENGTH_PRESETS2
|
|
2104
|
+
}
|
|
2105
|
+
]
|
|
2106
|
+
},
|
|
2107
|
+
{
|
|
2108
|
+
name: "mstts:express-as",
|
|
2109
|
+
aliases: ["express-as", "expressAs"],
|
|
2110
|
+
description: "Applies a speaking style, style degree, or role to the enclosed text.",
|
|
2111
|
+
parameters: [
|
|
2112
|
+
{
|
|
2113
|
+
name: "style",
|
|
2114
|
+
description: "The speaking style supported by the selected voice, such as `cheerful`.",
|
|
2115
|
+
example: SSML_PRESET_EXAMPLES2.expressAsStyle
|
|
2116
|
+
},
|
|
2117
|
+
{
|
|
2118
|
+
name: "styledegree",
|
|
2119
|
+
aliases: ["style-degree", "styleDegree"],
|
|
2120
|
+
description: "Controls the intensity of the selected speaking style.",
|
|
2121
|
+
example: "1.5"
|
|
2122
|
+
},
|
|
2123
|
+
{
|
|
2124
|
+
name: "role",
|
|
2125
|
+
description: "Changes the speaking role when supported by the selected voice.",
|
|
2126
|
+
example: "YoungAdultFemale"
|
|
2127
|
+
}
|
|
2128
|
+
]
|
|
2129
|
+
},
|
|
2130
|
+
{
|
|
2131
|
+
name: "say-as",
|
|
2132
|
+
aliases: ["sayAs"],
|
|
2133
|
+
description: "Controls how the enclosed text is interpreted and spoken.",
|
|
2134
|
+
parameters: [
|
|
2135
|
+
{
|
|
2136
|
+
name: "interpret-as",
|
|
2137
|
+
description: "Specifies the interpretation, such as characters, digits, date, or time.",
|
|
2138
|
+
example: "characters"
|
|
2139
|
+
},
|
|
2140
|
+
{
|
|
2141
|
+
name: "format",
|
|
2142
|
+
description: "Provides a format hint for the selected interpretation."
|
|
2143
|
+
},
|
|
2144
|
+
{
|
|
2145
|
+
name: "detail",
|
|
2146
|
+
description: "Provides an additional detail hint for the selected interpretation."
|
|
2147
|
+
}
|
|
2148
|
+
]
|
|
2149
|
+
},
|
|
2150
|
+
{
|
|
2151
|
+
name: "phoneme",
|
|
2152
|
+
description: "Replaces normal pronunciation with the supplied phonetic pronunciation.",
|
|
2153
|
+
parameters: [
|
|
2154
|
+
{
|
|
2155
|
+
name: "alphabet",
|
|
2156
|
+
description: "The phonetic alphabet used by the `ph` value.",
|
|
2157
|
+
values: PHONEME_ALPHABET_PRESETS2,
|
|
2158
|
+
example: SSML_PRESET_EXAMPLES2.phonemeAlphabet
|
|
2159
|
+
},
|
|
2160
|
+
{
|
|
2161
|
+
name: "ph",
|
|
2162
|
+
description: "The phonetic pronunciation for the enclosed text.",
|
|
2163
|
+
example: "h\u0259\u02C8lo\u028A"
|
|
2164
|
+
}
|
|
2165
|
+
]
|
|
2166
|
+
},
|
|
2167
|
+
{
|
|
2168
|
+
name: "emphasis",
|
|
2169
|
+
description: "Adds emphasis to the enclosed text.",
|
|
2170
|
+
parameters: [
|
|
2171
|
+
{
|
|
2172
|
+
name: "level",
|
|
2173
|
+
description: "Controls the amount of emphasis.",
|
|
2174
|
+
values: EMPHASIS_LEVEL_PRESETS2
|
|
2175
|
+
}
|
|
2176
|
+
]
|
|
2177
|
+
},
|
|
2178
|
+
{
|
|
2179
|
+
name: "audio",
|
|
2180
|
+
description: "Plays an audio file as part of the synthesized output.",
|
|
2181
|
+
parameters: [
|
|
2182
|
+
{
|
|
2183
|
+
name: "src",
|
|
2184
|
+
description: "The URI of the audio file.",
|
|
2185
|
+
example: "https://example.com/intro.wav"
|
|
2186
|
+
},
|
|
2187
|
+
{
|
|
2188
|
+
name: "desc",
|
|
2189
|
+
description: "Alternative text to use if the audio cannot be played."
|
|
2190
|
+
},
|
|
2191
|
+
{
|
|
2192
|
+
name: "clipBegin",
|
|
2193
|
+
description: "The starting offset within the audio file.",
|
|
2194
|
+
example: "0s"
|
|
2195
|
+
},
|
|
2196
|
+
{
|
|
2197
|
+
name: "clipEnd",
|
|
2198
|
+
description: "The ending offset within the audio file.",
|
|
2199
|
+
example: "5s"
|
|
2200
|
+
},
|
|
2201
|
+
{
|
|
2202
|
+
name: "speed",
|
|
2203
|
+
description: "The playback speed of the audio file.",
|
|
2204
|
+
example: "1.0"
|
|
2205
|
+
},
|
|
2206
|
+
{
|
|
2207
|
+
name: "repeatCount",
|
|
2208
|
+
description: "The number of times to repeat the audio.",
|
|
2209
|
+
example: "2"
|
|
2210
|
+
},
|
|
2211
|
+
{
|
|
2212
|
+
name: "repeatDuration",
|
|
2213
|
+
description: "The total duration for which the audio may repeat.",
|
|
2214
|
+
example: "10s"
|
|
2215
|
+
},
|
|
2216
|
+
{
|
|
2217
|
+
name: "soundLevel",
|
|
2218
|
+
description: "The audio volume adjustment in decibels.",
|
|
2219
|
+
example: "-3dB"
|
|
2220
|
+
}
|
|
2221
|
+
]
|
|
2222
|
+
},
|
|
2223
|
+
{
|
|
2224
|
+
name: "sub",
|
|
2225
|
+
description: "Substitutes the alias text when speaking the enclosed text.",
|
|
2226
|
+
parameters: [
|
|
2227
|
+
{
|
|
2228
|
+
name: "alias",
|
|
2229
|
+
description: "The text to speak instead of the enclosed text.",
|
|
2230
|
+
example: "World Wide Web"
|
|
2231
|
+
}
|
|
2232
|
+
]
|
|
2233
|
+
},
|
|
2234
|
+
{
|
|
2235
|
+
name: "lang",
|
|
2236
|
+
description: "Changes the language used for the enclosed text.",
|
|
2237
|
+
parameters: [
|
|
2238
|
+
{
|
|
2239
|
+
name: "xml:lang",
|
|
2240
|
+
aliases: ["lang"],
|
|
2241
|
+
description: "The BCP-47 language tag.",
|
|
2242
|
+
example: "ja-JP"
|
|
2243
|
+
}
|
|
2244
|
+
]
|
|
2245
|
+
},
|
|
2246
|
+
{
|
|
2247
|
+
name: "mark",
|
|
2248
|
+
description: "Inserts a custom marker into the synthesized audio stream.",
|
|
2249
|
+
parameters: [
|
|
2250
|
+
{
|
|
2251
|
+
name: "name",
|
|
2252
|
+
description: "The application-defined marker name.",
|
|
2253
|
+
example: "chapter-1"
|
|
2254
|
+
}
|
|
2255
|
+
]
|
|
2256
|
+
},
|
|
2257
|
+
{
|
|
2258
|
+
name: "bookmark",
|
|
2259
|
+
description: "Inserts a bookmark marker into the synthesized audio stream.",
|
|
2260
|
+
parameters: [
|
|
2261
|
+
{
|
|
2262
|
+
name: "mark",
|
|
2263
|
+
description: "The application-defined bookmark name.",
|
|
2264
|
+
example: "chapter-1"
|
|
2265
|
+
}
|
|
2266
|
+
]
|
|
2267
|
+
},
|
|
2268
|
+
{
|
|
2269
|
+
name: "lexicon",
|
|
2270
|
+
description: "Associates a pronunciation lexicon with the synthesized document.",
|
|
2271
|
+
parameters: [
|
|
2272
|
+
{
|
|
2273
|
+
name: "uri",
|
|
2274
|
+
description: "The URI of the pronunciation lexicon.",
|
|
2275
|
+
example: "https://example.com/lexicon.pls"
|
|
2276
|
+
}
|
|
2277
|
+
]
|
|
2278
|
+
},
|
|
2279
|
+
{
|
|
2280
|
+
name: "p",
|
|
2281
|
+
description: "Groups text into a paragraph.",
|
|
2282
|
+
parameters: []
|
|
2283
|
+
},
|
|
2284
|
+
{
|
|
2285
|
+
name: "s",
|
|
2286
|
+
description: "Groups text into a sentence.",
|
|
2287
|
+
parameters: []
|
|
2288
|
+
},
|
|
2289
|
+
{
|
|
2290
|
+
name: "w",
|
|
2291
|
+
description: "Groups text into a word.",
|
|
2292
|
+
parameters: []
|
|
2293
|
+
},
|
|
2294
|
+
{
|
|
2295
|
+
name: "mstts:silence",
|
|
2296
|
+
aliases: ["silence"],
|
|
2297
|
+
description: "Adds a specified silence before or after text or at a punctuation boundary.",
|
|
2298
|
+
parameters: [
|
|
2299
|
+
{
|
|
2300
|
+
name: "type",
|
|
2301
|
+
description: "The silence position or punctuation boundary.",
|
|
2302
|
+
values: SILENCE_TYPE_PRESETS2
|
|
2303
|
+
},
|
|
2304
|
+
{
|
|
2305
|
+
name: "value",
|
|
2306
|
+
description: "The silence duration, for example `300ms`.",
|
|
2307
|
+
example: SSML_PRESET_EXAMPLES2.silenceValue
|
|
2308
|
+
}
|
|
2309
|
+
]
|
|
2310
|
+
},
|
|
2311
|
+
{
|
|
2312
|
+
name: "mstts:viseme",
|
|
2313
|
+
aliases: ["viseme"],
|
|
2314
|
+
description: "Requests viseme events for the synthesized audio.",
|
|
2315
|
+
parameters: [
|
|
2316
|
+
{
|
|
2317
|
+
name: "type",
|
|
2318
|
+
description: "The viseme event format.",
|
|
2319
|
+
values: VISEME_TYPE_PRESETS2
|
|
2320
|
+
}
|
|
2321
|
+
]
|
|
2322
|
+
}
|
|
2323
|
+
];
|
|
2324
|
+
var definitionsByName = /* @__PURE__ */ new Map();
|
|
2325
|
+
for (const definition of SSML_TAG_DEFINITIONS) {
|
|
2326
|
+
definitionsByName.set(definition.name, definition);
|
|
2327
|
+
for (const alias of definition.aliases ?? []) {
|
|
2328
|
+
definitionsByName.set(alias, definition);
|
|
2329
|
+
}
|
|
2330
|
+
}
|
|
2331
|
+
function isXmlNameStart3(value) {
|
|
2332
|
+
return value !== void 0 && /[A-Za-z_]/.test(value);
|
|
2333
|
+
}
|
|
2334
|
+
function isXmlNameCharacter3(value) {
|
|
2335
|
+
return value !== void 0 && /[A-Za-z0-9_.:-]/.test(value);
|
|
2336
|
+
}
|
|
2337
|
+
function isXmlWhitespace3(value) {
|
|
2338
|
+
return value === " " || value === " " || value === "\r" || value === "\n";
|
|
2339
|
+
}
|
|
2340
|
+
function positionToOffset(source, lineNumber, column) {
|
|
2341
|
+
if (!Number.isInteger(lineNumber) || !Number.isInteger(column) || lineNumber < 1 || column < 1) {
|
|
2342
|
+
return void 0;
|
|
2343
|
+
}
|
|
2344
|
+
let lineStart = 0;
|
|
2345
|
+
for (let line = 1; line < lineNumber; line += 1) {
|
|
2346
|
+
const newline = source.indexOf("\n", lineStart);
|
|
2347
|
+
if (newline === -1) {
|
|
2348
|
+
return void 0;
|
|
2349
|
+
}
|
|
2350
|
+
lineStart = newline + 1;
|
|
2351
|
+
}
|
|
2352
|
+
const lineEnd = source.indexOf("\n", lineStart);
|
|
2353
|
+
const lineLength = lineEnd === -1 ? source.length - lineStart : lineEnd - lineStart;
|
|
2354
|
+
if (column > lineLength + 1) {
|
|
2355
|
+
return void 0;
|
|
2356
|
+
}
|
|
2357
|
+
return lineStart + column - 1;
|
|
2358
|
+
}
|
|
2359
|
+
function offsetToPosition(source, offset) {
|
|
2360
|
+
const lastNewline = source.lastIndexOf("\n", offset - 1);
|
|
2361
|
+
const lineNumber = source.slice(0, offset).split("\n").length;
|
|
2362
|
+
return {
|
|
2363
|
+
lineNumber,
|
|
2364
|
+
column: offset - lastNewline
|
|
2365
|
+
};
|
|
2366
|
+
}
|
|
2367
|
+
function toRange(source, token) {
|
|
2368
|
+
const start = offsetToPosition(source, token.start);
|
|
2369
|
+
const end = offsetToPosition(source, token.end);
|
|
2370
|
+
return {
|
|
2371
|
+
startLineNumber: start.lineNumber,
|
|
2372
|
+
startColumn: start.column,
|
|
2373
|
+
endLineNumber: end.lineNumber,
|
|
2374
|
+
endColumn: end.column
|
|
2375
|
+
};
|
|
2376
|
+
}
|
|
2377
|
+
function containsOffset(token, offset) {
|
|
2378
|
+
return offset >= token.start && offset < token.end;
|
|
2379
|
+
}
|
|
2380
|
+
function findTagEnd2(source, start) {
|
|
2381
|
+
let quote;
|
|
2382
|
+
for (let index = start; index < source.length; index += 1) {
|
|
2383
|
+
const character = source[index];
|
|
2384
|
+
if (quote !== void 0) {
|
|
2385
|
+
if (character === quote) {
|
|
2386
|
+
quote = void 0;
|
|
2387
|
+
}
|
|
2388
|
+
} else if (character === '"' || character === "'") {
|
|
2389
|
+
quote = character;
|
|
2390
|
+
} else if (character === ">") {
|
|
2391
|
+
return index;
|
|
2392
|
+
}
|
|
2393
|
+
}
|
|
2394
|
+
return void 0;
|
|
2395
|
+
}
|
|
2396
|
+
function parseTag(source, start, contentEnd, tokenEnd) {
|
|
2397
|
+
let index = start + 1;
|
|
2398
|
+
let closing = false;
|
|
2399
|
+
if (source[index] === "/") {
|
|
2400
|
+
closing = true;
|
|
2401
|
+
index += 1;
|
|
2402
|
+
}
|
|
2403
|
+
while (index < contentEnd && isXmlWhitespace3(source[index])) {
|
|
2404
|
+
index += 1;
|
|
2405
|
+
}
|
|
2406
|
+
if (!isXmlNameStart3(source[index])) {
|
|
2407
|
+
return void 0;
|
|
2408
|
+
}
|
|
2409
|
+
const nameStart = index;
|
|
2410
|
+
index += 1;
|
|
2411
|
+
while (index < contentEnd && isXmlNameCharacter3(source[index])) {
|
|
2412
|
+
index += 1;
|
|
2413
|
+
}
|
|
2414
|
+
const nameEnd = index;
|
|
2415
|
+
const attributes = [];
|
|
2416
|
+
if (!closing) {
|
|
2417
|
+
while (index < contentEnd) {
|
|
2418
|
+
while (index < contentEnd && isXmlWhitespace3(source[index])) {
|
|
2419
|
+
index += 1;
|
|
2420
|
+
}
|
|
2421
|
+
if (index >= contentEnd || source[index] === "/") {
|
|
2422
|
+
break;
|
|
2423
|
+
}
|
|
2424
|
+
if (!isXmlNameStart3(source[index])) {
|
|
2425
|
+
index += 1;
|
|
2426
|
+
continue;
|
|
2427
|
+
}
|
|
2428
|
+
const attributeStart = index;
|
|
2429
|
+
index += 1;
|
|
2430
|
+
while (index < contentEnd && isXmlNameCharacter3(source[index])) {
|
|
2431
|
+
index += 1;
|
|
2432
|
+
}
|
|
2433
|
+
const attributeEnd = index;
|
|
2434
|
+
while (index < contentEnd && isXmlWhitespace3(source[index])) {
|
|
2435
|
+
index += 1;
|
|
2436
|
+
}
|
|
2437
|
+
let value;
|
|
2438
|
+
if (source[index] === "=") {
|
|
2439
|
+
index += 1;
|
|
2440
|
+
while (index < contentEnd && isXmlWhitespace3(source[index])) {
|
|
2441
|
+
index += 1;
|
|
2442
|
+
}
|
|
2443
|
+
const quote = source[index];
|
|
2444
|
+
if (quote === '"' || quote === "'") {
|
|
2445
|
+
index += 1;
|
|
2446
|
+
const valueStart = index;
|
|
2447
|
+
while (index < contentEnd && source[index] !== quote) {
|
|
2448
|
+
index += 1;
|
|
2449
|
+
}
|
|
2450
|
+
value = { start: valueStart, end: index };
|
|
2451
|
+
if (index < contentEnd) {
|
|
2452
|
+
index += 1;
|
|
2453
|
+
}
|
|
2454
|
+
} else {
|
|
2455
|
+
const valueStart = index;
|
|
2456
|
+
while (index < contentEnd && !isXmlWhitespace3(source[index]) && source[index] !== "/") {
|
|
2457
|
+
index += 1;
|
|
2458
|
+
}
|
|
2459
|
+
value = { start: valueStart, end: index };
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
attributes.push({
|
|
2463
|
+
name: { start: attributeStart, end: attributeEnd },
|
|
2464
|
+
value
|
|
2465
|
+
});
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
return {
|
|
2469
|
+
name: source.slice(nameStart, nameEnd),
|
|
2470
|
+
nameRange: { start: nameStart, end: nameEnd },
|
|
2471
|
+
start,
|
|
2472
|
+
end: tokenEnd,
|
|
2473
|
+
closing,
|
|
2474
|
+
attributes
|
|
2475
|
+
};
|
|
2476
|
+
}
|
|
2477
|
+
function findTagAtOffset(source, offset) {
|
|
2478
|
+
let searchStart = 0;
|
|
2479
|
+
while (searchStart < source.length) {
|
|
2480
|
+
const start = source.indexOf("<", searchStart);
|
|
2481
|
+
if (start === -1 || start > offset) {
|
|
2482
|
+
return void 0;
|
|
2483
|
+
}
|
|
2484
|
+
if (source.startsWith("<!--", start)) {
|
|
2485
|
+
const commentEnd = source.indexOf("-->", start + 4);
|
|
2486
|
+
const tokenEnd2 = commentEnd === -1 ? source.length : commentEnd + 3;
|
|
2487
|
+
if (offset < tokenEnd2) {
|
|
2488
|
+
return void 0;
|
|
2489
|
+
}
|
|
2490
|
+
searchStart = tokenEnd2;
|
|
2491
|
+
continue;
|
|
2492
|
+
}
|
|
2493
|
+
if (source.startsWith("<![CDATA[", start)) {
|
|
2494
|
+
const cdataEnd = source.indexOf("]]>", start + 9);
|
|
2495
|
+
const tokenEnd2 = cdataEnd === -1 ? source.length : cdataEnd + 3;
|
|
2496
|
+
if (offset < tokenEnd2) {
|
|
2497
|
+
return void 0;
|
|
2498
|
+
}
|
|
2499
|
+
searchStart = tokenEnd2;
|
|
2500
|
+
continue;
|
|
2501
|
+
}
|
|
2502
|
+
if (source.startsWith("<?", start)) {
|
|
2503
|
+
const processingEnd = source.indexOf("?>", start + 2);
|
|
2504
|
+
const tokenEnd2 = processingEnd === -1 ? source.length : processingEnd + 2;
|
|
2505
|
+
if (offset < tokenEnd2) {
|
|
2506
|
+
return void 0;
|
|
2507
|
+
}
|
|
2508
|
+
searchStart = tokenEnd2;
|
|
2509
|
+
continue;
|
|
2510
|
+
}
|
|
2511
|
+
const tagEnd = findTagEnd2(source, start + 1);
|
|
2512
|
+
const contentEnd = tagEnd ?? source.length;
|
|
2513
|
+
const tokenEnd = tagEnd === void 0 ? source.length : tagEnd + 1;
|
|
2514
|
+
if (offset < tokenEnd) {
|
|
2515
|
+
return parseTag(source, start, contentEnd, tokenEnd);
|
|
2516
|
+
}
|
|
2517
|
+
if (tagEnd === void 0) {
|
|
2518
|
+
return void 0;
|
|
2519
|
+
}
|
|
2520
|
+
searchStart = tokenEnd;
|
|
2521
|
+
}
|
|
2522
|
+
return void 0;
|
|
2523
|
+
}
|
|
2524
|
+
function findParameter(definition, name) {
|
|
2525
|
+
return definition.parameters.find(
|
|
2526
|
+
(parameter) => parameter.name === name || parameter.aliases?.includes(name) === true
|
|
2527
|
+
);
|
|
2528
|
+
}
|
|
2529
|
+
function getSsmlTagDefinition(name) {
|
|
2530
|
+
return definitionsByName.get(name);
|
|
2531
|
+
}
|
|
2532
|
+
function findSsmlHoverTarget(source, lineNumber, column) {
|
|
2533
|
+
const offset = positionToOffset(source, lineNumber, column);
|
|
2534
|
+
if (offset === void 0) {
|
|
2535
|
+
return void 0;
|
|
2536
|
+
}
|
|
2537
|
+
const tag = findTagAtOffset(source, offset);
|
|
2538
|
+
if (!tag) {
|
|
2539
|
+
return void 0;
|
|
2540
|
+
}
|
|
2541
|
+
const definition = getSsmlTagDefinition(tag.name);
|
|
2542
|
+
if (!definition) {
|
|
2543
|
+
return void 0;
|
|
2544
|
+
}
|
|
2545
|
+
if (containsOffset(tag.nameRange, offset)) {
|
|
2546
|
+
return {
|
|
2547
|
+
kind: "tag",
|
|
2548
|
+
tagName: tag.name,
|
|
2549
|
+
isClosingTag: tag.closing,
|
|
2550
|
+
definition,
|
|
2551
|
+
range: toRange(source, tag.nameRange)
|
|
2552
|
+
};
|
|
2553
|
+
}
|
|
2554
|
+
for (const attribute of tag.attributes) {
|
|
2555
|
+
if (containsOffset(attribute.name, offset)) {
|
|
2556
|
+
const parameter = findParameter(definition, source.slice(attribute.name.start, attribute.name.end));
|
|
2557
|
+
if (!parameter) {
|
|
2558
|
+
return void 0;
|
|
2559
|
+
}
|
|
2560
|
+
return {
|
|
2561
|
+
kind: "parameter",
|
|
2562
|
+
tagName: tag.name,
|
|
2563
|
+
isClosingTag: tag.closing,
|
|
2564
|
+
definition,
|
|
2565
|
+
parameter,
|
|
2566
|
+
range: toRange(source, attribute.name)
|
|
2567
|
+
};
|
|
2568
|
+
}
|
|
2569
|
+
if (attribute.value && containsOffset(attribute.value, offset)) {
|
|
2570
|
+
const parameter = findParameter(definition, source.slice(attribute.name.start, attribute.name.end));
|
|
2571
|
+
if (!parameter) {
|
|
2572
|
+
return void 0;
|
|
2573
|
+
}
|
|
2574
|
+
return {
|
|
2575
|
+
kind: "parameter-value",
|
|
2576
|
+
tagName: tag.name,
|
|
2577
|
+
isClosingTag: tag.closing,
|
|
2578
|
+
definition,
|
|
2579
|
+
parameter,
|
|
2580
|
+
range: toRange(source, attribute.value)
|
|
2581
|
+
};
|
|
2582
|
+
}
|
|
2583
|
+
}
|
|
2584
|
+
return void 0;
|
|
2585
|
+
}
|
|
2586
|
+
function code(value) {
|
|
2587
|
+
return `\`${value.replace(/\\/g, "\\\\").replace(/`/g, "\\`")}\``;
|
|
2588
|
+
}
|
|
2589
|
+
function formatParameter(parameter, tagName, locale) {
|
|
2590
|
+
const localizedParameter = SSML_HOVER_COPY[locale].tags[tagName]?.parameters[parameter.name];
|
|
2591
|
+
const description = localizedParameter?.description ?? parameter.description;
|
|
2592
|
+
const values = parameter.values && parameter.values.length > 0 ? ` ${SSML_HOVER_COPY[locale].allowedValues}: ${parameter.values.map(code).join(", ")}.` : "";
|
|
2593
|
+
const example = parameter.example ? ` ${SSML_HOVER_COPY[locale].example}: ${code(parameter.example)}.` : "";
|
|
2594
|
+
return `- ${code(parameter.name)}: ${description}${values}${example}`;
|
|
2595
|
+
}
|
|
2596
|
+
function formatSsmlHover(target, locale = "en") {
|
|
2597
|
+
const localizedTag = SSML_HOVER_COPY[locale].tags[target.definition.name];
|
|
2598
|
+
const tagTitle = localizedTag?.title ?? target.definition.name;
|
|
2599
|
+
const tagDescription = localizedTag?.description ?? target.definition.description;
|
|
2600
|
+
const tagSyntax = target.isClosingTag ? `</${target.tagName}>` : `<${target.tagName}>`;
|
|
2601
|
+
const lines = [`### ${code(tagSyntax)}`, "", `**${tagTitle}**`, "", tagDescription];
|
|
2602
|
+
if (target.parameter) {
|
|
2603
|
+
const localizedParameter = localizedTag?.parameters[target.parameter.name];
|
|
2604
|
+
const parameterTitle = localizedParameter?.title ?? target.parameter.name;
|
|
2605
|
+
const parameterDescription = localizedParameter?.description ?? target.parameter.description;
|
|
2606
|
+
lines.push("", `**${SSML_HOVER_COPY[locale].parameterHeading} ${code(parameterTitle)}**`, "", parameterDescription);
|
|
2607
|
+
if (target.parameter.values && target.parameter.values.length > 0) {
|
|
2608
|
+
lines.push("", `${SSML_HOVER_COPY[locale].allowedValues}: ${target.parameter.values.map(code).join(", ")}.`);
|
|
2609
|
+
}
|
|
2610
|
+
if (target.parameter.example) {
|
|
2611
|
+
lines.push("", `${SSML_HOVER_COPY[locale].example}: ${code(target.parameter.example)}.`);
|
|
2612
|
+
}
|
|
2613
|
+
} else if (target.definition.parameters.length > 0) {
|
|
2614
|
+
lines.push(
|
|
2615
|
+
"",
|
|
2616
|
+
`**${SSML_HOVER_COPY[locale].parametersHeading}**`,
|
|
2617
|
+
"",
|
|
2618
|
+
...target.definition.parameters.map((parameter) => formatParameter(parameter, target.definition.name, locale))
|
|
2619
|
+
);
|
|
2620
|
+
} else {
|
|
2621
|
+
lines.push("", SSML_HOVER_COPY[locale].noParameters);
|
|
2622
|
+
}
|
|
2623
|
+
return lines.join("\n");
|
|
2624
|
+
}
|
|
2625
|
+
|
|
2626
|
+
// packages/ssml-editor-react/src/constants/ui.ts
|
|
2627
|
+
var DEFAULT_LOCALE = "ja";
|
|
2628
|
+
var OVERLAY_Z_INDEX = 9999;
|
|
2629
|
+
var SELECTION_OVERLAY_ABOVE_THRESHOLD_LINES = 4;
|
|
2630
|
+
var SSML_INSERTION_MODES = {
|
|
2631
|
+
insert: "insert",
|
|
2632
|
+
wrap: "wrap"
|
|
2633
|
+
};
|
|
2634
|
+
|
|
2635
|
+
// packages/ssml-editor-react/src/ssmlInsertion.ts
|
|
2636
|
+
function isLineStart(value, offset) {
|
|
2637
|
+
return offset === 0 || value[offset - 1] === "\n" || value[offset - 1] === "\r";
|
|
2638
|
+
}
|
|
2639
|
+
function isLineEnd(value, offset) {
|
|
2640
|
+
return offset === value.length || value[offset] === "\n" || value[offset] === "\r";
|
|
2641
|
+
}
|
|
2642
|
+
function startsWithLineBreak(value) {
|
|
2643
|
+
return value.startsWith("\n") || value.startsWith("\r");
|
|
2644
|
+
}
|
|
2645
|
+
function endsWithLineBreak(value) {
|
|
2646
|
+
return value.endsWith("\n") || value.endsWith("\r");
|
|
2647
|
+
}
|
|
2648
|
+
function createSsmlInsertionEdit(source, startOffset, endOffset, template) {
|
|
2649
|
+
const selectedText = source.slice(startOffset, endOffset);
|
|
2650
|
+
if (template.mode === SSML_INSERTION_MODES.wrap) {
|
|
2651
|
+
return {
|
|
2652
|
+
replacement: `${template.prefix}${selectedText}${template.suffix}`,
|
|
2653
|
+
selectionOffset: template.prefix.length
|
|
2654
|
+
};
|
|
2655
|
+
}
|
|
2656
|
+
const leadingLineBreak = !isLineStart(source, startOffset) && !startsWithLineBreak(template.prefix) ? "\n" : "";
|
|
2657
|
+
const needsTrailingLineBreak = selectedText.length > 0 ? !selectedText.startsWith("\n") && !selectedText.startsWith("\r") : !isLineEnd(source, endOffset);
|
|
2658
|
+
const trailingLineBreak = needsTrailingLineBreak && !endsWithLineBreak(template.prefix) ? "\n" : "";
|
|
2659
|
+
const insertionPrefix = `${leadingLineBreak}${template.prefix}`;
|
|
2660
|
+
return {
|
|
2661
|
+
replacement: `${insertionPrefix}${trailingLineBreak}${selectedText}`,
|
|
2662
|
+
selectionOffset: insertionPrefix.length + (selectedText.length > 0 ? trailingLineBreak.length : 0)
|
|
2663
|
+
};
|
|
2664
|
+
}
|
|
2665
|
+
|
|
2666
|
+
// packages/ssml-editor-react/src/SsmlEditor.tsx
|
|
2667
|
+
var SSML_MARKER_OWNER = "ssml-builder";
|
|
2668
|
+
var UNGROUPED_TOOLBAR_GROUP = "__ssml-editor-ungrouped__";
|
|
2669
|
+
var EDITABLE_SSML_PREFIX = '<speak version="1.0" xml:lang="en-US">';
|
|
2670
|
+
var EDITABLE_SSML_SUFFIX = "</speak>";
|
|
2671
|
+
function localizedText(value) {
|
|
2672
|
+
return { ja: value, en: value };
|
|
2673
|
+
}
|
|
2674
|
+
function escapeXmlAttribute(value) {
|
|
2675
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">").replace(/'/g, "'");
|
|
2676
|
+
}
|
|
2677
|
+
function createSsmlEditorInsertionDefinition(definition) {
|
|
2678
|
+
const mode = definition.mode ?? "wrap";
|
|
2679
|
+
const attribute = definition.attribute ? ` ${definition.attribute}="` : "";
|
|
2680
|
+
return {
|
|
2681
|
+
id: definition.id,
|
|
2682
|
+
icon: definition.icon ?? "\uFF0B",
|
|
2683
|
+
tagName: definition.tagName,
|
|
2684
|
+
selfClosing: mode === "insert",
|
|
2685
|
+
labels: definition.labels,
|
|
2686
|
+
titles: definition.titles,
|
|
2687
|
+
descriptions: definition.descriptions ?? localizedText(`Inserts the <${definition.tagName}> element.`),
|
|
2688
|
+
parameterDescription: definition.parameterDescription ?? localizedText(`Selects the value for the <${definition.tagName}> element.`),
|
|
2689
|
+
options: definition.options,
|
|
2690
|
+
createTemplate: (value) => {
|
|
2691
|
+
const attributeValue = definition.attribute ? `${attribute}${escapeXmlAttribute(value)}"` : "";
|
|
2692
|
+
if (mode === "wrap") {
|
|
2693
|
+
return {
|
|
2694
|
+
prefix: `<${definition.tagName}${attributeValue}>`,
|
|
2695
|
+
suffix: `</${definition.tagName}>`,
|
|
2696
|
+
mode
|
|
2697
|
+
};
|
|
2698
|
+
}
|
|
2699
|
+
return {
|
|
2700
|
+
prefix: `<${definition.tagName}${attributeValue}/>`,
|
|
2701
|
+
suffix: "",
|
|
2702
|
+
mode
|
|
2703
|
+
};
|
|
2704
|
+
}
|
|
2705
|
+
};
|
|
2706
|
+
}
|
|
2707
|
+
function createInsertionOptions(values, descriptions) {
|
|
2708
|
+
return values.map((value) => ({
|
|
2709
|
+
value,
|
|
2710
|
+
labels: { ja: value, en: value },
|
|
2711
|
+
...descriptions?.[value] ? { descriptions: descriptions[value] } : {}
|
|
2712
|
+
}));
|
|
2713
|
+
}
|
|
2714
|
+
var SSML_INSERTIONS = [
|
|
2715
|
+
{
|
|
2716
|
+
id: "break",
|
|
2717
|
+
icon: "\u23F8",
|
|
2718
|
+
tagName: "break",
|
|
2719
|
+
selfClosing: true,
|
|
2720
|
+
labels: { ja: "\u9593", en: "Break" },
|
|
2721
|
+
descriptions: {
|
|
2722
|
+
ja: "\u6307\u5B9A\u3057\u305F\u6642\u9593\u3060\u3051\u7121\u97F3\u306E\u9593\u3092\u633F\u5165\u3057\u307E\u3059\u3002",
|
|
2723
|
+
en: "Inserts a silent pause for the selected duration."
|
|
2724
|
+
},
|
|
2725
|
+
parameterDescription: {
|
|
2726
|
+
ja: "\u7121\u97F3\u306B\u3059\u308B\u6642\u9593\u3092\u9078\u629E\u3057\u307E\u3059\u3002",
|
|
2727
|
+
en: "Selects the duration of the silent pause."
|
|
2728
|
+
},
|
|
2729
|
+
options: createInsertionOptions(BREAK_TIME_PRESETS, BREAK_TIME_DESCRIPTIONS),
|
|
2730
|
+
createTemplate: (value) => ({
|
|
2731
|
+
prefix: `<break time="${value}"/>`,
|
|
2732
|
+
suffix: "",
|
|
2733
|
+
mode: "insert"
|
|
2734
|
+
})
|
|
2735
|
+
},
|
|
2736
|
+
{
|
|
2737
|
+
id: "emphasis",
|
|
2738
|
+
icon: "\u2726",
|
|
2739
|
+
tagName: "emphasis",
|
|
2740
|
+
labels: { ja: "\u5F37\u8ABF", en: "Emphasis" },
|
|
2741
|
+
descriptions: {
|
|
2742
|
+
ja: "\u9078\u629E\u7BC4\u56F2\u306E\u5F37\u8ABF\u30EC\u30D9\u30EB\u3092\u5909\u66F4\u3057\u307E\u3059\u3002",
|
|
2743
|
+
en: "Changes the emphasis level of the selected text."
|
|
2744
|
+
},
|
|
2745
|
+
parameterDescription: {
|
|
2746
|
+
ja: "\u9078\u629E\u7BC4\u56F2\u306E\u5F37\u8ABF\u30EC\u30D9\u30EB\u3092\u9078\u629E\u3057\u307E\u3059\u3002",
|
|
2747
|
+
en: "Selects the emphasis level for the selected text."
|
|
2748
|
+
},
|
|
2749
|
+
options: createInsertionOptions(EMPHASIS_LEVEL_PRESETS, EMPHASIS_LEVEL_DESCRIPTIONS),
|
|
2750
|
+
createTemplate: (value) => ({
|
|
2751
|
+
prefix: `<emphasis level="${value}">`,
|
|
2752
|
+
suffix: "</emphasis>",
|
|
2753
|
+
mode: "wrap"
|
|
2754
|
+
})
|
|
2755
|
+
},
|
|
2756
|
+
{
|
|
2757
|
+
id: "rate",
|
|
2758
|
+
icon: "\u2195",
|
|
2759
|
+
tagName: "prosody",
|
|
2760
|
+
labels: { ja: "\u901F\u5EA6", en: "Rate" },
|
|
2761
|
+
descriptions: {
|
|
2762
|
+
ja: "\u9078\u629E\u7BC4\u56F2\u306E\u8AAD\u307F\u4E0A\u3052\u901F\u5EA6\u3092\u5909\u66F4\u3057\u307E\u3059\u3002",
|
|
2763
|
+
en: "Changes the speech rate of the selected text."
|
|
2764
|
+
},
|
|
2765
|
+
parameterDescription: {
|
|
2766
|
+
ja: "\u9078\u629E\u7BC4\u56F2\u306E\u8AAD\u307F\u4E0A\u3052\u901F\u5EA6\u3092\u9078\u629E\u3057\u307E\u3059\u3002",
|
|
2767
|
+
en: "Selects the speech rate for the selected text."
|
|
2768
|
+
},
|
|
2769
|
+
options: createInsertionOptions(PROSODY_RATE_PRESETS, PROSODY_RATE_DESCRIPTIONS),
|
|
2770
|
+
createTemplate: (value) => ({
|
|
2771
|
+
prefix: `<prosody rate="${value}">`,
|
|
2772
|
+
suffix: "</prosody>",
|
|
2773
|
+
mode: "wrap"
|
|
2774
|
+
})
|
|
2775
|
+
},
|
|
2776
|
+
{
|
|
2777
|
+
id: "pitch",
|
|
2778
|
+
icon: "\u2197",
|
|
2779
|
+
tagName: "prosody",
|
|
2780
|
+
labels: { ja: "\u9AD8\u3055", en: "Pitch" },
|
|
2781
|
+
descriptions: {
|
|
2782
|
+
ja: "\u9078\u629E\u7BC4\u56F2\u306E\u58F0\u306E\u9AD8\u3055\u3092\u5909\u66F4\u3057\u307E\u3059\u3002",
|
|
2783
|
+
en: "Changes the pitch of the selected text."
|
|
2784
|
+
},
|
|
2785
|
+
parameterDescription: {
|
|
2786
|
+
ja: "\u9078\u629E\u7BC4\u56F2\u306E\u58F0\u306E\u9AD8\u3055\u3092\u534A\u97F3\u5358\u4F4D\u3067\u9078\u629E\u3057\u307E\u3059\u3002",
|
|
2787
|
+
en: "Selects the pitch adjustment in semitone steps."
|
|
2788
|
+
},
|
|
2789
|
+
options: createInsertionOptions(PROSODY_PITCH_PRESETS, PROSODY_PITCH_DESCRIPTIONS),
|
|
2790
|
+
createTemplate: (value) => ({
|
|
2791
|
+
prefix: `<prosody pitch="${value}">`,
|
|
2792
|
+
suffix: "</prosody>",
|
|
2793
|
+
mode: "wrap"
|
|
2794
|
+
})
|
|
2795
|
+
},
|
|
2796
|
+
{
|
|
2797
|
+
id: "volume",
|
|
2798
|
+
icon: "\u{1F50A}",
|
|
2799
|
+
tagName: "prosody",
|
|
2800
|
+
labels: { ja: "\u97F3\u91CF", en: "Volume" },
|
|
2801
|
+
descriptions: {
|
|
2802
|
+
ja: "\u9078\u629E\u7BC4\u56F2\u306E\u97F3\u91CF\u3092\u5909\u66F4\u3057\u307E\u3059\u3002",
|
|
2803
|
+
en: "Changes the volume of the selected text."
|
|
2804
|
+
},
|
|
2805
|
+
parameterDescription: {
|
|
2806
|
+
ja: "\u9078\u629E\u7BC4\u56F2\u306E\u97F3\u91CF\u30EC\u30D9\u30EB\u3092\u9078\u629E\u3057\u307E\u3059\u3002",
|
|
2807
|
+
en: "Selects the volume level for the selected text."
|
|
2808
|
+
},
|
|
2809
|
+
options: createInsertionOptions(PROSODY_VOLUME_PRESETS, PROSODY_VOLUME_DESCRIPTIONS),
|
|
2810
|
+
createTemplate: (value) => ({
|
|
2811
|
+
prefix: `<prosody volume="${value}">`,
|
|
2812
|
+
suffix: "</prosody>",
|
|
2813
|
+
mode: "wrap"
|
|
2814
|
+
})
|
|
2815
|
+
},
|
|
2816
|
+
{
|
|
2817
|
+
id: "emotion",
|
|
2818
|
+
icon: "\u263A",
|
|
2819
|
+
tagName: "mstts:express-as",
|
|
2820
|
+
labels: { ja: "\u611F\u60C5", en: "Emotion" },
|
|
2821
|
+
descriptions: {
|
|
2822
|
+
ja: "\u9078\u629E\u7BC4\u56F2\u306B\u97F3\u58F0\u306E\u611F\u60C5\u30B9\u30BF\u30A4\u30EB\u3092\u9069\u7528\u3057\u307E\u3059\u3002",
|
|
2823
|
+
en: "Applies a voice emotion style to the selected text."
|
|
2824
|
+
},
|
|
2825
|
+
parameterDescription: {
|
|
2826
|
+
ja: "\u9078\u629E\u7BC4\u56F2\u306B\u9069\u7528\u3059\u308B\u97F3\u58F0\u306E\u611F\u60C5\u30B9\u30BF\u30A4\u30EB\u3092\u9078\u629E\u3057\u307E\u3059\u3002",
|
|
2827
|
+
en: "Selects the voice emotion style to apply."
|
|
2828
|
+
},
|
|
2829
|
+
options: createInsertionOptions(EXPRESS_AS_STYLE_PRESETS, EXPRESS_AS_STYLE_DESCRIPTIONS),
|
|
2830
|
+
createTemplate: (value) => ({
|
|
2831
|
+
prefix: `<mstts:express-as style="${value}">`,
|
|
2832
|
+
suffix: "</mstts:express-as>",
|
|
2833
|
+
mode: "wrap"
|
|
2834
|
+
})
|
|
2835
|
+
},
|
|
2836
|
+
{
|
|
2837
|
+
id: "say-as",
|
|
2838
|
+
icon: "Aa",
|
|
2839
|
+
tagName: "say-as",
|
|
2840
|
+
labels: { ja: "\u8AAD\u307F\u4E0A\u3052", en: "Say as" },
|
|
2841
|
+
descriptions: {
|
|
2842
|
+
ja: "\u6570\u5B57\u3084\u65E5\u4ED8\u306A\u3069\u306E\u8AAD\u307F\u4E0A\u3052\u65B9\u3092\u6307\u5B9A\u3057\u307E\u3059\u3002",
|
|
2843
|
+
en: "Specifies how values such as numbers or dates are spoken."
|
|
2844
|
+
},
|
|
2845
|
+
parameterDescription: {
|
|
2846
|
+
ja: "\u9078\u629E\u7BC4\u56F2\u306E\u8AAD\u307F\u4E0A\u3052\u65B9\u3092\u9078\u629E\u3057\u307E\u3059\u3002",
|
|
2847
|
+
en: "Selects how the selected text is spoken."
|
|
2848
|
+
},
|
|
2849
|
+
options: createInsertionOptions(SAY_AS_PRESETS, SAY_AS_DESCRIPTIONS),
|
|
2850
|
+
createTemplate: (value) => ({
|
|
2851
|
+
prefix: `<say-as interpret-as="${value}">`,
|
|
2852
|
+
suffix: "</say-as>",
|
|
2853
|
+
mode: "wrap"
|
|
2854
|
+
})
|
|
2855
|
+
},
|
|
2856
|
+
{
|
|
2857
|
+
id: "lang",
|
|
2858
|
+
icon: "\u6587",
|
|
2859
|
+
tagName: "lang",
|
|
2860
|
+
labels: { ja: "\u8A00\u8A9E", en: "Language" },
|
|
2861
|
+
descriptions: {
|
|
2862
|
+
ja: "\u9078\u629E\u7BC4\u56F2\u306E\u8AAD\u307F\u4E0A\u3052\u8A00\u8A9E\u3092\u5909\u66F4\u3057\u307E\u3059\u3002",
|
|
2863
|
+
en: "Changes the speaking language of the selected text."
|
|
2864
|
+
},
|
|
2865
|
+
parameterDescription: {
|
|
2866
|
+
ja: "\u9078\u629E\u7BC4\u56F2\u306B\u9069\u7528\u3059\u308B BCP-47 \u8A00\u8A9E\u30BF\u30B0\u3092\u9078\u629E\u3057\u307E\u3059\u3002",
|
|
2867
|
+
en: "Selects the BCP-47 language tag for the selected text."
|
|
2868
|
+
},
|
|
2869
|
+
options: createInsertionOptions(LANGUAGE_PRESETS, LANGUAGE_DESCRIPTIONS),
|
|
2870
|
+
createTemplate: (value) => ({
|
|
2871
|
+
prefix: `<lang xml:lang="${value}">`,
|
|
2872
|
+
suffix: "</lang>",
|
|
2873
|
+
mode: "wrap"
|
|
2874
|
+
})
|
|
2875
|
+
},
|
|
2876
|
+
{
|
|
2877
|
+
id: "mstts:silence",
|
|
2878
|
+
icon: "\u23F3",
|
|
2879
|
+
tagName: "mstts:silence",
|
|
2880
|
+
selfClosing: true,
|
|
2881
|
+
labels: { ja: "\u7121\u97F3", en: "Silence" },
|
|
2882
|
+
descriptions: {
|
|
2883
|
+
ja: "\u7121\u97F3\u6642\u9593\u3092\u633F\u5165\u3057\u307E\u3059\u3002",
|
|
2884
|
+
en: "Inserts a silence interval."
|
|
2885
|
+
},
|
|
2886
|
+
parameterDescription: {
|
|
2887
|
+
ja: "\u7121\u97F3\u306B\u3059\u308B\u6642\u9593\u3092\u9078\u629E\u3057\u307E\u3059\u3002",
|
|
2888
|
+
en: "Selects the silence duration."
|
|
2889
|
+
},
|
|
2890
|
+
options: createInsertionOptions(SILENCE_VALUE_PRESETS, SILENCE_VALUE_DESCRIPTIONS),
|
|
2891
|
+
createTemplate: (value) => ({
|
|
2892
|
+
prefix: `<mstts:silence type="Leading" value="${value}"/>`,
|
|
2893
|
+
suffix: "",
|
|
2894
|
+
mode: "insert"
|
|
2895
|
+
})
|
|
2896
|
+
}
|
|
2897
|
+
];
|
|
2898
|
+
var DEFAULT_INSERTION_GROUPS = [
|
|
2899
|
+
{
|
|
2900
|
+
id: "pauses",
|
|
2901
|
+
labels: { ja: "\u9593\u30FB\u7121\u97F3", en: "Pauses" },
|
|
2902
|
+
insertionIds: ["break", "mstts:silence"]
|
|
2903
|
+
},
|
|
2904
|
+
{
|
|
2905
|
+
id: "prosody",
|
|
2906
|
+
labels: { ja: "\u58F0\u306E\u8ABF\u6574", en: "Voice" },
|
|
2907
|
+
insertionIds: ["rate", "pitch", "volume"]
|
|
2908
|
+
},
|
|
2909
|
+
{
|
|
2910
|
+
id: "expression",
|
|
2911
|
+
labels: { ja: "\u8868\u73FE", en: "Expression" },
|
|
2912
|
+
insertionIds: ["emphasis", "emotion"]
|
|
2913
|
+
},
|
|
2914
|
+
{
|
|
2915
|
+
id: "pronunciation",
|
|
2916
|
+
labels: { ja: "\u8AAD\u307F\u4E0A\u3052", en: "Pronunciation" },
|
|
2917
|
+
insertionIds: ["say-as", "lang"]
|
|
2918
|
+
}
|
|
2919
|
+
];
|
|
2920
|
+
function createDefaultToolbarGroups(insertionGroups) {
|
|
2921
|
+
return [
|
|
2922
|
+
{
|
|
2923
|
+
id: "history",
|
|
2924
|
+
buttonIds: ["undo", "redo"]
|
|
2925
|
+
},
|
|
2926
|
+
...insertionGroups.map(({ id, insertionIds }) => ({
|
|
2927
|
+
id,
|
|
2928
|
+
buttonIds: insertionIds
|
|
2929
|
+
})),
|
|
2930
|
+
{
|
|
2931
|
+
id: "document",
|
|
2932
|
+
buttonIds: ["clearAll", "format", "decorations"]
|
|
2933
|
+
},
|
|
2934
|
+
{
|
|
2935
|
+
id: "help",
|
|
2936
|
+
buttonIds: ["help"]
|
|
2937
|
+
}
|
|
2938
|
+
];
|
|
2939
|
+
}
|
|
2940
|
+
function getInsertionCollection(collection) {
|
|
2941
|
+
if (!collection) {
|
|
2942
|
+
return [];
|
|
2943
|
+
}
|
|
2944
|
+
return Array.isArray(collection) ? collection : Object.values(collection).filter((insertion) => insertion !== void 0);
|
|
2945
|
+
}
|
|
2946
|
+
function getConfiguredInsertions(emotionStyles, customInsertions, additionalInsertions) {
|
|
2947
|
+
const insertions = /* @__PURE__ */ new Map();
|
|
2948
|
+
for (const insertion of SSML_INSERTIONS) {
|
|
2949
|
+
if (insertion.id === "emotion" && emotionStyles !== void 0) {
|
|
2950
|
+
insertions.set(insertion.id, {
|
|
2951
|
+
...insertion,
|
|
2952
|
+
options: createInsertionOptions(emotionStyles)
|
|
2953
|
+
});
|
|
2954
|
+
continue;
|
|
2955
|
+
}
|
|
2956
|
+
insertions.set(insertion.id, insertion);
|
|
2957
|
+
}
|
|
2958
|
+
const normalizeInsertion = (insertion) => "createTemplate" in insertion ? insertion : createSsmlEditorInsertionDefinition(insertion);
|
|
2959
|
+
for (const insertion of getInsertionCollection(additionalInsertions)) {
|
|
2960
|
+
const normalized = normalizeInsertion(insertion);
|
|
2961
|
+
if (!insertions.has(normalized.id)) {
|
|
2962
|
+
insertions.set(normalized.id, normalized);
|
|
2963
|
+
}
|
|
2964
|
+
}
|
|
2965
|
+
for (const insertion of getInsertionCollection(customInsertions)) {
|
|
2966
|
+
const normalized = normalizeInsertion(insertion);
|
|
2967
|
+
insertions.set(normalized.id, normalized);
|
|
2968
|
+
}
|
|
2969
|
+
return [...insertions.values()];
|
|
2970
|
+
}
|
|
2971
|
+
function orderInsertions(insertions, insertionOrder) {
|
|
2972
|
+
if (!insertionOrder || insertionOrder.length === 0) {
|
|
2973
|
+
return insertions;
|
|
2974
|
+
}
|
|
2975
|
+
const insertionsById = new Map(insertions.map((insertion) => [insertion.id, insertion]));
|
|
2976
|
+
const ordered = [];
|
|
2977
|
+
const included = /* @__PURE__ */ new Set();
|
|
2978
|
+
for (const id of insertionOrder) {
|
|
2979
|
+
const insertion = insertionsById.get(id);
|
|
2980
|
+
if (insertion && !included.has(id)) {
|
|
2981
|
+
ordered.push(insertion);
|
|
2982
|
+
included.add(id);
|
|
2983
|
+
}
|
|
2984
|
+
}
|
|
2985
|
+
for (const insertion of insertions) {
|
|
2986
|
+
if (!included.has(insertion.id)) {
|
|
2987
|
+
ordered.push(insertion);
|
|
2988
|
+
}
|
|
2989
|
+
}
|
|
2990
|
+
return ordered;
|
|
2991
|
+
}
|
|
2992
|
+
function orderToolbarButtons(buttonIds, toolbarOrder) {
|
|
2993
|
+
if (!toolbarOrder || toolbarOrder.length === 0) {
|
|
2994
|
+
return buttonIds;
|
|
2995
|
+
}
|
|
2996
|
+
const available = new Set(buttonIds);
|
|
2997
|
+
const ordered = [];
|
|
2998
|
+
const included = /* @__PURE__ */ new Set();
|
|
2999
|
+
for (const id of toolbarOrder) {
|
|
3000
|
+
if (available.has(id) && !included.has(id)) {
|
|
3001
|
+
ordered.push(id);
|
|
3002
|
+
included.add(id);
|
|
3003
|
+
}
|
|
3004
|
+
}
|
|
3005
|
+
for (const id of buttonIds) {
|
|
3006
|
+
if (!included.has(id)) {
|
|
3007
|
+
ordered.push(id);
|
|
3008
|
+
}
|
|
3009
|
+
}
|
|
3010
|
+
return ordered;
|
|
3011
|
+
}
|
|
3012
|
+
function getInsertionTitle(insertion, language) {
|
|
3013
|
+
if (insertion.titles) {
|
|
3014
|
+
return insertion.titles[language];
|
|
3015
|
+
}
|
|
3016
|
+
const tag = insertion.tagName ? ` <${insertion.tagName}${insertion.selfClosing ? "/>" : ">"}` : "";
|
|
3017
|
+
return `${insertion.labels[language]}${tag} \u2014 ${insertion.descriptions[language]}`;
|
|
3018
|
+
}
|
|
3019
|
+
var STYLE_ID = "ssml-editor-theme";
|
|
3020
|
+
var STYLE_CSS = `
|
|
3021
|
+
[data-ssml-editor] {
|
|
3022
|
+
--ssml-editor-color: #111827;
|
|
3023
|
+
--ssml-editor-bg: #ffffff;
|
|
3024
|
+
--ssml-editor-border: #d1d5db;
|
|
3025
|
+
--ssml-editor-control-bg: #f9fafb;
|
|
3026
|
+
--ssml-editor-control-border: #9ca3af;
|
|
3027
|
+
--ssml-editor-preview-bg: #f3f4f6;
|
|
3028
|
+
--ssml-editor-error: #b91c1c;
|
|
3029
|
+
--ssml-editor-error-bg: #fef2f2;
|
|
3030
|
+
--ssml-editor-switch-active: #2563eb;
|
|
3031
|
+
--ssml-editor-pause-badge-bg: #e0e7ff;
|
|
3032
|
+
--ssml-editor-pause-badge-color: #3730a3;
|
|
3033
|
+
--ssml-editor-pause-badge-border: #c7d2fe;
|
|
3034
|
+
--ssml-editor-prosody-badge-bg: #dcfce7;
|
|
3035
|
+
--ssml-editor-prosody-badge-color: #166534;
|
|
3036
|
+
--ssml-editor-prosody-badge-border: #86efac;
|
|
3037
|
+
}
|
|
3038
|
+
[data-ssml-editor][data-theme="dark"] {
|
|
3039
|
+
--ssml-editor-color: #f9fafb;
|
|
3040
|
+
--ssml-editor-bg: #1f2937;
|
|
3041
|
+
--ssml-editor-border: #374151;
|
|
3042
|
+
--ssml-editor-control-bg: #111827;
|
|
3043
|
+
--ssml-editor-control-border: #4b5563;
|
|
3044
|
+
--ssml-editor-preview-bg: #111827;
|
|
3045
|
+
--ssml-editor-error: #fca5a5;
|
|
3046
|
+
--ssml-editor-error-bg: #450a0a;
|
|
3047
|
+
--ssml-editor-switch-active: #60a5fa;
|
|
3048
|
+
--ssml-editor-pause-badge-bg: #312e81;
|
|
3049
|
+
--ssml-editor-pause-badge-color: #c7d2fe;
|
|
3050
|
+
--ssml-editor-pause-badge-border: #6366f1;
|
|
3051
|
+
--ssml-editor-prosody-badge-bg: #14532d;
|
|
3052
|
+
--ssml-editor-prosody-badge-color: #bbf7d0;
|
|
3053
|
+
--ssml-editor-prosody-badge-border: #4ade80;
|
|
3054
|
+
}
|
|
3055
|
+
[data-ssml-editor] .ssml-editor-inline-badge {
|
|
3056
|
+
display: inline-block;
|
|
3057
|
+
margin-left: 0.35em;
|
|
3058
|
+
padding: 0 0.35em;
|
|
3059
|
+
border: 1px solid;
|
|
3060
|
+
border-radius: 999px;
|
|
3061
|
+
font-size: 0.75em;
|
|
3062
|
+
font-weight: 600;
|
|
3063
|
+
line-height: 1.4;
|
|
3064
|
+
white-space: nowrap;
|
|
3065
|
+
vertical-align: middle;
|
|
3066
|
+
pointer-events: none;
|
|
3067
|
+
}
|
|
3068
|
+
[data-ssml-editor] .ssml-editor-inline-badge-pause {
|
|
3069
|
+
color: var(--ssml-editor-pause-badge-color);
|
|
3070
|
+
background-color: var(--ssml-editor-pause-badge-bg);
|
|
3071
|
+
border-color: var(--ssml-editor-pause-badge-border);
|
|
3072
|
+
}
|
|
3073
|
+
[data-ssml-editor] .ssml-editor-inline-badge-prosody {
|
|
3074
|
+
color: var(--ssml-editor-prosody-badge-color);
|
|
3075
|
+
background-color: var(--ssml-editor-prosody-badge-bg);
|
|
3076
|
+
border-color: var(--ssml-editor-prosody-badge-border);
|
|
3077
|
+
}
|
|
3078
|
+
[data-ssml-editor] .ssml-editor-switch-track[aria-checked="true"] {
|
|
3079
|
+
background-color: var(--ssml-editor-switch-active);
|
|
3080
|
+
}
|
|
3081
|
+
[data-ssml-editor] .ssml-editor-switch-track[aria-checked="true"] .ssml-editor-switch-thumb {
|
|
3082
|
+
transform: translateX(1.25rem);
|
|
3083
|
+
}
|
|
3084
|
+
[data-ssml-editor] .ssml-editor-switch-track:focus-visible {
|
|
3085
|
+
outline: 2px solid var(--ssml-editor-switch-active);
|
|
3086
|
+
outline-offset: 2px;
|
|
3087
|
+
}
|
|
3088
|
+
[data-ssml-editor] .ssml-editor-help-settings-summary {
|
|
3089
|
+
list-style: none;
|
|
3090
|
+
}
|
|
3091
|
+
[data-ssml-editor] .ssml-editor-help-settings-summary::-webkit-details-marker {
|
|
3092
|
+
display: none;
|
|
3093
|
+
}
|
|
3094
|
+
[data-ssml-editor] .ssml-editor-help-settings-summary:hover {
|
|
3095
|
+
background-color: var(--ssml-editor-preview-bg);
|
|
3096
|
+
}
|
|
3097
|
+
[data-ssml-editor] .ssml-editor-help-settings-summary:focus-visible {
|
|
3098
|
+
outline: 2px solid var(--ssml-editor-control-border);
|
|
3099
|
+
outline-offset: -2px;
|
|
3100
|
+
}
|
|
3101
|
+
[data-ssml-editor] .ssml-editor-help-settings-summary::before {
|
|
3102
|
+
content: "\u25B8";
|
|
3103
|
+
display: inline-flex;
|
|
3104
|
+
align-items: center;
|
|
3105
|
+
justify-content: center;
|
|
3106
|
+
font-size: 1rem;
|
|
3107
|
+
line-height: 1.45;
|
|
3108
|
+
}
|
|
3109
|
+
[data-ssml-editor]
|
|
3110
|
+
.ssml-editor-help-settings-accordion[open]
|
|
3111
|
+
> .ssml-editor-help-settings-summary::before {
|
|
3112
|
+
content: "\u25BE";
|
|
3113
|
+
}
|
|
3114
|
+
`.trim();
|
|
3115
|
+
function injectEditorTheme() {
|
|
3116
|
+
if (typeof document !== "undefined" && !document.getElementById(STYLE_ID)) {
|
|
3117
|
+
const style = document.createElement("style");
|
|
3118
|
+
style.id = STYLE_ID;
|
|
3119
|
+
style.textContent = STYLE_CSS;
|
|
3120
|
+
document.head.appendChild(style);
|
|
3121
|
+
}
|
|
3122
|
+
}
|
|
3123
|
+
var styles = {
|
|
3124
|
+
container: {
|
|
3125
|
+
display: "grid",
|
|
3126
|
+
gap: "0.75rem",
|
|
3127
|
+
padding: "1rem",
|
|
3128
|
+
border: "1px solid var(--ssml-editor-border)",
|
|
3129
|
+
borderRadius: "0.5rem",
|
|
3130
|
+
color: "var(--ssml-editor-color)",
|
|
3131
|
+
backgroundColor: "var(--ssml-editor-bg)"
|
|
3132
|
+
},
|
|
3133
|
+
toolbarContainer: {
|
|
3134
|
+
display: "flex",
|
|
3135
|
+
alignItems: "center",
|
|
3136
|
+
flexWrap: "wrap",
|
|
3137
|
+
gap: "0.5rem"
|
|
3138
|
+
},
|
|
3139
|
+
toolbarActions: {
|
|
3140
|
+
display: "flex",
|
|
3141
|
+
alignItems: "center",
|
|
3142
|
+
flexWrap: "wrap",
|
|
3143
|
+
gap: "0.5rem"
|
|
3144
|
+
},
|
|
3145
|
+
toolbarSeparator: {
|
|
3146
|
+
width: "1px",
|
|
3147
|
+
height: "2.25rem",
|
|
3148
|
+
margin: "0 0.25rem",
|
|
3149
|
+
backgroundColor: "var(--ssml-editor-border)"
|
|
3150
|
+
},
|
|
3151
|
+
toolbarDropdown: {
|
|
3152
|
+
position: "relative",
|
|
3153
|
+
display: "inline-block"
|
|
3154
|
+
},
|
|
3155
|
+
toolbarSwitch: {
|
|
3156
|
+
display: "inline-flex",
|
|
3157
|
+
alignItems: "center",
|
|
3158
|
+
gap: "0.375rem",
|
|
3159
|
+
minHeight: "2.25rem",
|
|
3160
|
+
color: "var(--ssml-editor-color)",
|
|
3161
|
+
font: "inherit"
|
|
3162
|
+
},
|
|
3163
|
+
toolbarSwitchTrack: {
|
|
3164
|
+
display: "inline-flex",
|
|
3165
|
+
alignItems: "center",
|
|
3166
|
+
width: "2.75rem",
|
|
3167
|
+
height: "1.5rem",
|
|
3168
|
+
padding: "0.1875rem",
|
|
3169
|
+
border: 0,
|
|
3170
|
+
borderRadius: "999px",
|
|
3171
|
+
backgroundColor: "var(--ssml-editor-control-border)",
|
|
3172
|
+
cursor: "pointer",
|
|
3173
|
+
font: "inherit",
|
|
3174
|
+
transition: "background-color 0.2s ease"
|
|
3175
|
+
},
|
|
3176
|
+
toolbarSwitchThumb: {
|
|
3177
|
+
width: "1.125rem",
|
|
3178
|
+
height: "1.125rem",
|
|
3179
|
+
borderRadius: "50%",
|
|
3180
|
+
backgroundColor: "var(--ssml-editor-bg)",
|
|
3181
|
+
transition: "transform 0.2s ease"
|
|
3182
|
+
},
|
|
3183
|
+
toolbarButton: {
|
|
3184
|
+
display: "inline-flex",
|
|
3185
|
+
alignItems: "center",
|
|
3186
|
+
gap: "0.375rem",
|
|
3187
|
+
minHeight: "2.25rem",
|
|
3188
|
+
padding: "0.375rem 0.625rem",
|
|
3189
|
+
border: "1px solid var(--ssml-editor-control-border)",
|
|
3190
|
+
borderRadius: "0.25rem",
|
|
3191
|
+
color: "var(--ssml-editor-color)",
|
|
3192
|
+
backgroundColor: "var(--ssml-editor-control-bg)",
|
|
3193
|
+
font: "inherit",
|
|
3194
|
+
cursor: "pointer"
|
|
3195
|
+
},
|
|
3196
|
+
display: {
|
|
3197
|
+
display: "grid",
|
|
3198
|
+
gap: "0.5rem"
|
|
3199
|
+
},
|
|
3200
|
+
toolbarIconOnly: {
|
|
3201
|
+
justifyContent: "center",
|
|
3202
|
+
minWidth: "2.25rem",
|
|
3203
|
+
padding: "0.375rem"
|
|
3204
|
+
},
|
|
3205
|
+
toolbarIcon: {
|
|
3206
|
+
display: "inline-flex",
|
|
3207
|
+
width: "1.25rem",
|
|
3208
|
+
justifyContent: "center",
|
|
3209
|
+
fontSize: "1.1rem",
|
|
3210
|
+
lineHeight: 1
|
|
3211
|
+
},
|
|
3212
|
+
toolbarChevron: {
|
|
3213
|
+
fontSize: "0.7rem",
|
|
3214
|
+
lineHeight: 1
|
|
3215
|
+
},
|
|
3216
|
+
toolbarMenu: {
|
|
3217
|
+
position: "fixed",
|
|
3218
|
+
zIndex: OVERLAY_Z_INDEX,
|
|
3219
|
+
display: "grid",
|
|
3220
|
+
minWidth: "max-content",
|
|
3221
|
+
maxHeight: "min(24rem, calc(100vh - 1rem))",
|
|
3222
|
+
gap: "0.125rem",
|
|
3223
|
+
padding: "0.25rem",
|
|
3224
|
+
border: "1px solid var(--ssml-editor-control-border)",
|
|
3225
|
+
borderRadius: "0.25rem",
|
|
3226
|
+
backgroundColor: "var(--ssml-editor-control-bg)",
|
|
3227
|
+
boxShadow: "0 0.25rem 0.75rem rgb(0 0 0 / 20%)",
|
|
3228
|
+
overflowY: "auto"
|
|
3229
|
+
},
|
|
3230
|
+
toolbarOption: {
|
|
3231
|
+
padding: "0.375rem 0.5rem",
|
|
3232
|
+
border: 0,
|
|
3233
|
+
borderRadius: "0.125rem",
|
|
3234
|
+
color: "var(--ssml-editor-color)",
|
|
3235
|
+
backgroundColor: "transparent",
|
|
3236
|
+
font: "inherit",
|
|
3237
|
+
textAlign: "left",
|
|
3238
|
+
whiteSpace: "nowrap",
|
|
3239
|
+
cursor: "pointer"
|
|
3240
|
+
},
|
|
3241
|
+
helpPanel: {
|
|
3242
|
+
display: "grid",
|
|
3243
|
+
gap: "0.5rem",
|
|
3244
|
+
width: "100%",
|
|
3245
|
+
padding: "0.75rem",
|
|
3246
|
+
border: "1px solid var(--ssml-editor-control-border)",
|
|
3247
|
+
borderRadius: "0.25rem",
|
|
3248
|
+
backgroundColor: "var(--ssml-editor-preview-bg)"
|
|
3249
|
+
},
|
|
3250
|
+
helpHeading: {
|
|
3251
|
+
margin: 0,
|
|
3252
|
+
fontSize: "1rem"
|
|
3253
|
+
},
|
|
3254
|
+
helpDescription: {
|
|
3255
|
+
margin: 0,
|
|
3256
|
+
lineHeight: 1.5
|
|
3257
|
+
},
|
|
3258
|
+
helpList: {
|
|
3259
|
+
display: "grid",
|
|
3260
|
+
gap: "0.375rem",
|
|
3261
|
+
margin: 0,
|
|
3262
|
+
paddingLeft: "1.25rem"
|
|
3263
|
+
},
|
|
3264
|
+
helpItem: {
|
|
3265
|
+
listStyleType: "none",
|
|
3266
|
+
lineHeight: 1.45
|
|
3267
|
+
},
|
|
3268
|
+
helpIcon: {
|
|
3269
|
+
display: "inline-flex",
|
|
3270
|
+
width: "1.25rem",
|
|
3271
|
+
justifyContent: "center",
|
|
3272
|
+
fontSize: "1.1rem",
|
|
3273
|
+
lineHeight: 1.45
|
|
3274
|
+
},
|
|
3275
|
+
helpSettingsAccordion: {
|
|
3276
|
+
marginTop: "0.375rem",
|
|
3277
|
+
overflow: "hidden",
|
|
3278
|
+
border: "1px solid var(--ssml-editor-control-border)",
|
|
3279
|
+
borderRadius: "0.25rem",
|
|
3280
|
+
backgroundColor: "var(--ssml-editor-control-bg)"
|
|
3281
|
+
},
|
|
3282
|
+
helpSettingsSummary: {
|
|
3283
|
+
display: "grid",
|
|
3284
|
+
gridTemplateColumns: "1rem 1.25rem minmax(0, 1fr)",
|
|
3285
|
+
columnGap: "0.5rem",
|
|
3286
|
+
alignItems: "start",
|
|
3287
|
+
padding: "0.5rem 0.625rem",
|
|
3288
|
+
cursor: "pointer"
|
|
3289
|
+
},
|
|
3290
|
+
helpSettingsSummaryContent: {
|
|
3291
|
+
minWidth: 0
|
|
3292
|
+
},
|
|
3293
|
+
helpSettingsDescription: {
|
|
3294
|
+
margin: "0.5rem 0.75rem 0",
|
|
3295
|
+
fontSize: "0.875rem"
|
|
3296
|
+
},
|
|
3297
|
+
helpSettingsList: {
|
|
3298
|
+
display: "grid",
|
|
3299
|
+
gap: "0.125rem",
|
|
3300
|
+
margin: "0.25rem 0.75rem 0.75rem",
|
|
3301
|
+
paddingLeft: "1.25rem",
|
|
3302
|
+
fontSize: "0.875rem"
|
|
3303
|
+
},
|
|
3304
|
+
editor: {
|
|
3305
|
+
boxSizing: "border-box",
|
|
3306
|
+
position: "relative",
|
|
3307
|
+
width: "100%",
|
|
3308
|
+
minHeight: "8rem",
|
|
3309
|
+
border: "1px solid var(--ssml-editor-control-border)",
|
|
3310
|
+
borderRadius: "0.25rem",
|
|
3311
|
+
overflow: "visible"
|
|
3312
|
+
},
|
|
3313
|
+
selectionActions: {
|
|
3314
|
+
position: "absolute",
|
|
3315
|
+
zIndex: OVERLAY_Z_INDEX,
|
|
3316
|
+
display: "flex",
|
|
3317
|
+
alignItems: "center",
|
|
3318
|
+
flexWrap: "wrap",
|
|
3319
|
+
gap: "0.25rem",
|
|
3320
|
+
maxWidth: "calc(100% - 1rem)",
|
|
3321
|
+
padding: "0.25rem",
|
|
3322
|
+
border: "1px solid var(--ssml-editor-control-border)",
|
|
3323
|
+
borderRadius: "0.375rem",
|
|
3324
|
+
color: "var(--ssml-editor-color)",
|
|
3325
|
+
backgroundColor: "var(--ssml-editor-control-bg)",
|
|
3326
|
+
boxShadow: "0 0.25rem 0.75rem rgb(0 0 0 / 20%)"
|
|
3327
|
+
},
|
|
3328
|
+
selectionCount: {
|
|
3329
|
+
padding: "0.25rem 0.375rem",
|
|
3330
|
+
fontSize: "0.875rem",
|
|
3331
|
+
fontWeight: 600,
|
|
3332
|
+
whiteSpace: "nowrap"
|
|
3333
|
+
},
|
|
3334
|
+
selectionActionsDivider: {
|
|
3335
|
+
width: "1px",
|
|
3336
|
+
height: "1.5rem",
|
|
3337
|
+
backgroundColor: "var(--ssml-editor-border)"
|
|
3338
|
+
},
|
|
3339
|
+
selectionActionButton: {
|
|
3340
|
+
display: "inline-flex",
|
|
3341
|
+
alignItems: "center",
|
|
3342
|
+
gap: "0.25rem",
|
|
3343
|
+
minHeight: "1.75rem",
|
|
3344
|
+
padding: "0.25rem 0.375rem",
|
|
3345
|
+
border: "1px solid var(--ssml-editor-control-border)",
|
|
3346
|
+
borderRadius: "0.25rem",
|
|
3347
|
+
color: "var(--ssml-editor-color)",
|
|
3348
|
+
backgroundColor: "var(--ssml-editor-bg)",
|
|
3349
|
+
font: "inherit",
|
|
3350
|
+
fontSize: "0.875rem",
|
|
3351
|
+
cursor: "pointer"
|
|
3352
|
+
},
|
|
3353
|
+
selectionActionIcon: {
|
|
3354
|
+
display: "inline-flex",
|
|
3355
|
+
width: "1rem",
|
|
3356
|
+
justifyContent: "center",
|
|
3357
|
+
lineHeight: 1
|
|
3358
|
+
},
|
|
3359
|
+
error: {
|
|
3360
|
+
margin: 0,
|
|
3361
|
+
padding: "0.5rem 0.75rem",
|
|
3362
|
+
border: "1px solid var(--ssml-editor-error)",
|
|
3363
|
+
borderRadius: "0.25rem",
|
|
3364
|
+
color: "var(--ssml-editor-error)",
|
|
3365
|
+
backgroundColor: "var(--ssml-editor-error-bg)",
|
|
3366
|
+
lineHeight: 1.5
|
|
3367
|
+
}
|
|
3368
|
+
};
|
|
3369
|
+
function ToolbarInsertionMenu({
|
|
3370
|
+
insertion,
|
|
3371
|
+
language,
|
|
3372
|
+
isDarkTheme,
|
|
3373
|
+
showToolbarIcons,
|
|
3374
|
+
showToolbarText,
|
|
3375
|
+
toolbarButtonStyle,
|
|
3376
|
+
isReadOnly,
|
|
3377
|
+
onApply
|
|
3378
|
+
}) {
|
|
3379
|
+
const menuId = (0, import_react.useId)();
|
|
3380
|
+
const triggerRef = (0, import_react.useRef)(null);
|
|
3381
|
+
const menuRef = (0, import_react.useRef)(null);
|
|
3382
|
+
const [isOpen, setIsOpen] = (0, import_react.useState)(false);
|
|
3383
|
+
const [menuPosition, setMenuPosition] = (0, import_react.useState)(null);
|
|
3384
|
+
(0, import_react.useEffect)(() => {
|
|
3385
|
+
if (!isOpen) {
|
|
3386
|
+
setMenuPosition(null);
|
|
3387
|
+
return;
|
|
3388
|
+
}
|
|
3389
|
+
const updateMenuPosition = () => {
|
|
3390
|
+
const trigger = triggerRef.current;
|
|
3391
|
+
if (!trigger) {
|
|
3392
|
+
return;
|
|
3393
|
+
}
|
|
3394
|
+
const triggerBounds = trigger.getBoundingClientRect();
|
|
3395
|
+
setMenuPosition({
|
|
3396
|
+
top: triggerBounds.bottom + 4,
|
|
3397
|
+
left: triggerBounds.left
|
|
3398
|
+
});
|
|
3399
|
+
};
|
|
3400
|
+
const handlePointerDown = (event) => {
|
|
3401
|
+
const target = event.target;
|
|
3402
|
+
if (target instanceof Node && !triggerRef.current?.contains(target) && !menuRef.current?.contains(target)) {
|
|
3403
|
+
setIsOpen(false);
|
|
3404
|
+
}
|
|
3405
|
+
};
|
|
3406
|
+
const handleKeyDown = (event) => {
|
|
3407
|
+
if (event.key === "Escape") {
|
|
3408
|
+
setIsOpen(false);
|
|
3409
|
+
triggerRef.current?.focus();
|
|
3410
|
+
}
|
|
3411
|
+
};
|
|
3412
|
+
updateMenuPosition();
|
|
3413
|
+
window.addEventListener("resize", updateMenuPosition);
|
|
3414
|
+
window.addEventListener("scroll", updateMenuPosition, true);
|
|
3415
|
+
document.addEventListener("pointerdown", handlePointerDown);
|
|
3416
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
3417
|
+
return () => {
|
|
3418
|
+
window.removeEventListener("resize", updateMenuPosition);
|
|
3419
|
+
window.removeEventListener("scroll", updateMenuPosition, true);
|
|
3420
|
+
document.removeEventListener("pointerdown", handlePointerDown);
|
|
3421
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
3422
|
+
};
|
|
3423
|
+
}, [isOpen]);
|
|
3424
|
+
const menu = isOpen && menuPosition && typeof document !== "undefined" && /* @__PURE__ */ React.createElement(
|
|
3425
|
+
"div",
|
|
3426
|
+
{
|
|
3427
|
+
ref: menuRef,
|
|
3428
|
+
id: menuId,
|
|
3429
|
+
"data-ssml-editor": "",
|
|
3430
|
+
"data-theme": isDarkTheme ? "dark" : "light",
|
|
3431
|
+
style: { ...styles.toolbarMenu, top: menuPosition.top, left: menuPosition.left },
|
|
3432
|
+
role: "menu",
|
|
3433
|
+
"aria-label": insertion.labels[language]
|
|
3434
|
+
},
|
|
3435
|
+
insertion.options.map((option) => /* @__PURE__ */ React.createElement(
|
|
3436
|
+
"button",
|
|
3437
|
+
{
|
|
3438
|
+
key: option.value,
|
|
3439
|
+
type: "button",
|
|
3440
|
+
role: "menuitem",
|
|
3441
|
+
style: styles.toolbarOption,
|
|
3442
|
+
title: option.descriptions?.[language] ?? insertion.descriptions[language],
|
|
3443
|
+
disabled: isReadOnly,
|
|
3444
|
+
onMouseDown: (event) => event.preventDefault(),
|
|
3445
|
+
onClick: () => {
|
|
3446
|
+
if (!isReadOnly) {
|
|
3447
|
+
onApply(insertion, option);
|
|
3448
|
+
}
|
|
3449
|
+
setIsOpen(false);
|
|
3450
|
+
}
|
|
3451
|
+
},
|
|
3452
|
+
option.labels[language]
|
|
3453
|
+
))
|
|
3454
|
+
);
|
|
3455
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { style: styles.toolbarDropdown }, /* @__PURE__ */ React.createElement(
|
|
3456
|
+
"button",
|
|
3457
|
+
{
|
|
3458
|
+
ref: triggerRef,
|
|
3459
|
+
type: "button",
|
|
3460
|
+
style: toolbarButtonStyle,
|
|
3461
|
+
title: getInsertionTitle(insertion, language),
|
|
3462
|
+
"aria-label": insertion.labels[language],
|
|
3463
|
+
"aria-haspopup": "menu",
|
|
3464
|
+
"aria-expanded": isOpen,
|
|
3465
|
+
"aria-controls": isOpen ? menuId : void 0,
|
|
3466
|
+
onClick: () => setIsOpen((open) => !open)
|
|
3467
|
+
},
|
|
3468
|
+
showToolbarIcons && /* @__PURE__ */ React.createElement("span", { style: styles.toolbarIcon, "aria-hidden": "true" }, insertion.icon),
|
|
3469
|
+
showToolbarText && /* @__PURE__ */ React.createElement("span", null, insertion.labels[language]),
|
|
3470
|
+
/* @__PURE__ */ React.createElement("span", { style: styles.toolbarChevron, "aria-hidden": "true" }, "\u25BE")
|
|
3471
|
+
)), menu && (0, import_react_dom.createPortal)(menu, document.body));
|
|
3472
|
+
}
|
|
3473
|
+
function ToolbarDecorationsSwitch({
|
|
3474
|
+
copy,
|
|
3475
|
+
showToolbarIcons,
|
|
3476
|
+
showToolbarText,
|
|
3477
|
+
decorationsVisible,
|
|
3478
|
+
onVisibilityChange
|
|
3479
|
+
}) {
|
|
3480
|
+
return /* @__PURE__ */ React.createElement("div", { style: styles.toolbarSwitch }, showToolbarIcons && /* @__PURE__ */ React.createElement("span", { style: styles.toolbarIcon, "aria-hidden": "true" }, "\u2606"), showToolbarText && /* @__PURE__ */ React.createElement("span", null, copy.decorations), /* @__PURE__ */ React.createElement(
|
|
3481
|
+
"button",
|
|
3482
|
+
{
|
|
3483
|
+
type: "button",
|
|
3484
|
+
className: "ssml-editor-switch-track",
|
|
3485
|
+
style: styles.toolbarSwitchTrack,
|
|
3486
|
+
role: "switch",
|
|
3487
|
+
"aria-checked": decorationsVisible,
|
|
3488
|
+
"aria-label": copy.decorations,
|
|
3489
|
+
title: decorationsVisible ? copy.decorationsHideTitle : copy.decorationsShowTitle,
|
|
3490
|
+
onClick: () => onVisibilityChange(!decorationsVisible)
|
|
3491
|
+
},
|
|
3492
|
+
/* @__PURE__ */ React.createElement("span", { className: "ssml-editor-switch-thumb", style: styles.toolbarSwitchThumb, "aria-hidden": "true" })
|
|
3493
|
+
));
|
|
3494
|
+
}
|
|
3495
|
+
var EMPTY_SELECTION_OVERLAY = {
|
|
3496
|
+
selectedText: "",
|
|
3497
|
+
characterCount: 0,
|
|
3498
|
+
hasSelection: false,
|
|
3499
|
+
position: null,
|
|
3500
|
+
placement: "above"
|
|
3501
|
+
};
|
|
3502
|
+
var hoverProviderRegistrations = /* @__PURE__ */ new WeakMap();
|
|
3503
|
+
function updateSsmlMarkers(monaco, model, value, syntaxError) {
|
|
3504
|
+
if (!syntaxError) {
|
|
3505
|
+
monaco.editor.setModelMarkers(model, SSML_MARKER_OWNER, []);
|
|
3506
|
+
return;
|
|
3507
|
+
}
|
|
3508
|
+
const startOffset = value.length === 0 ? 0 : Math.min(syntaxError.offset, value.length - 1);
|
|
3509
|
+
const endOffset = Math.min(startOffset + 1, value.length);
|
|
3510
|
+
const start = model.getPositionAt(startOffset);
|
|
3511
|
+
const end = model.getPositionAt(endOffset);
|
|
3512
|
+
monaco.editor.setModelMarkers(model, SSML_MARKER_OWNER, [
|
|
3513
|
+
{
|
|
3514
|
+
message: syntaxError.message,
|
|
3515
|
+
severity: monaco.MarkerSeverity.Error,
|
|
3516
|
+
startLineNumber: start.lineNumber,
|
|
3517
|
+
startColumn: start.column,
|
|
3518
|
+
endLineNumber: end.lineNumber,
|
|
3519
|
+
endColumn: end.column
|
|
3520
|
+
}
|
|
3521
|
+
]);
|
|
3522
|
+
}
|
|
3523
|
+
function getSsmlAttributeValue(tag, attributeName) {
|
|
3524
|
+
const escapedAttributeName = attributeName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
3525
|
+
const match = tag.match(new RegExp(`\\b${escapedAttributeName}\\s*=\\s*("|')([^"']*)\\1`, "i"));
|
|
3526
|
+
return match?.[2];
|
|
3527
|
+
}
|
|
3528
|
+
function getSsmlInlineDecorations(model, value, language) {
|
|
3529
|
+
const decorations = [];
|
|
3530
|
+
const tagPattern = /<(break|prosody)\b[^>]*>/gi;
|
|
3531
|
+
const badgeCopy = INLINE_BADGE_COPY[language];
|
|
3532
|
+
for (const match of value.matchAll(tagPattern)) {
|
|
3533
|
+
const tag = match[0];
|
|
3534
|
+
const tagName = match[1].toLowerCase();
|
|
3535
|
+
const startOffset = match.index ?? 0;
|
|
3536
|
+
const endOffset = startOffset + tag.length;
|
|
3537
|
+
const start = model.getPositionAt(startOffset);
|
|
3538
|
+
const end = model.getPositionAt(endOffset);
|
|
3539
|
+
const pauseValue = getSsmlAttributeValue(tag, "time") ?? getSsmlAttributeValue(tag, "strength");
|
|
3540
|
+
const pitchValue = getSsmlAttributeValue(tag, "pitch") ?? getSsmlAttributeValue(tag, "contour") ?? getSsmlAttributeValue(tag, "range");
|
|
3541
|
+
const prosodyValue = pitchValue ?? getSsmlAttributeValue(tag, "rate") ?? getSsmlAttributeValue(tag, "volume");
|
|
3542
|
+
const badge = tagName === "break" ? `${badgeCopy.pause}${pauseValue ? ` ${pauseValue}` : ""}` : `${pitchValue ? badgeCopy.pitch : badgeCopy.prosody}${prosodyValue ? ` ${prosodyValue}` : ""}`;
|
|
3543
|
+
decorations.push({
|
|
3544
|
+
range: {
|
|
3545
|
+
startLineNumber: start.lineNumber,
|
|
3546
|
+
startColumn: start.column,
|
|
3547
|
+
endLineNumber: end.lineNumber,
|
|
3548
|
+
endColumn: end.column
|
|
3549
|
+
},
|
|
3550
|
+
options: {
|
|
3551
|
+
after: {
|
|
3552
|
+
content: ` ${badge}`,
|
|
3553
|
+
inlineClassName: `ssml-editor-inline-badge ssml-editor-inline-badge-${tagName === "break" ? "pause" : "prosody"}`
|
|
3554
|
+
}
|
|
3555
|
+
}
|
|
3556
|
+
});
|
|
3557
|
+
}
|
|
3558
|
+
return decorations;
|
|
3559
|
+
}
|
|
3560
|
+
function updateSsmlInlineDecorations(model, value, language, decorationIds) {
|
|
3561
|
+
return model.deltaDecorations(decorationIds, getSsmlInlineDecorations(model, value, language));
|
|
3562
|
+
}
|
|
3563
|
+
function clearSsmlInlineDecorations(model, decorationIds) {
|
|
3564
|
+
return model.deltaDecorations(decorationIds, []);
|
|
3565
|
+
}
|
|
3566
|
+
function syncSsmlInlineDecorations(model, value, language, showDecorations, decorationIds) {
|
|
3567
|
+
return showDecorations ? updateSsmlInlineDecorations(model, value, language, decorationIds) : clearSsmlInlineDecorations(model, decorationIds);
|
|
3568
|
+
}
|
|
3569
|
+
function isSsmlElement(node) {
|
|
3570
|
+
return typeof node !== "string" && node.type !== "text";
|
|
3571
|
+
}
|
|
3572
|
+
function isVoice(element) {
|
|
3573
|
+
return element.type === "voice";
|
|
3574
|
+
}
|
|
3575
|
+
function isProsody(element) {
|
|
3576
|
+
return element.type === "prosody";
|
|
3577
|
+
}
|
|
3578
|
+
function getDocumentChildren2(document2) {
|
|
3579
|
+
return document2.children ?? (document2.content === void 0 ? [] : [document2.content]);
|
|
3580
|
+
}
|
|
3581
|
+
function getPartialContext(document2) {
|
|
3582
|
+
const children = getDocumentChildren2(document2);
|
|
3583
|
+
const voice = findFirstElement(children, isVoice);
|
|
3584
|
+
const prosody = findFirstElement(children, isProsody);
|
|
3585
|
+
const context = {
|
|
3586
|
+
version: document2.version,
|
|
3587
|
+
lang: document2.lang
|
|
3588
|
+
};
|
|
3589
|
+
if (voice) {
|
|
3590
|
+
context.voice = {
|
|
3591
|
+
name: voice.name,
|
|
3592
|
+
effect: voice.effect,
|
|
3593
|
+
attributes: voice.attributes
|
|
3594
|
+
};
|
|
3595
|
+
}
|
|
3596
|
+
if (prosody) {
|
|
3597
|
+
context.prosody = {
|
|
3598
|
+
rate: prosody.rate,
|
|
3599
|
+
pitch: prosody.pitch,
|
|
3600
|
+
volume: prosody.volume,
|
|
3601
|
+
contour: prosody.contour,
|
|
3602
|
+
range: prosody.range,
|
|
3603
|
+
attributes: prosody.attributes
|
|
3604
|
+
};
|
|
3605
|
+
}
|
|
3606
|
+
return context;
|
|
3607
|
+
}
|
|
3608
|
+
function findFirstElement(nodes, predicate) {
|
|
3609
|
+
for (const node of nodes) {
|
|
3610
|
+
if (!isSsmlElement(node)) {
|
|
3611
|
+
continue;
|
|
3612
|
+
}
|
|
3613
|
+
if (predicate(node)) {
|
|
3614
|
+
return node;
|
|
3615
|
+
}
|
|
3616
|
+
const child = findFirstElement(node.children ?? [], predicate);
|
|
3617
|
+
if (child) {
|
|
3618
|
+
return child;
|
|
3619
|
+
}
|
|
3620
|
+
}
|
|
3621
|
+
return void 0;
|
|
3622
|
+
}
|
|
3623
|
+
function updateFirstElement(nodes, predicate, update) {
|
|
3624
|
+
let updated = false;
|
|
3625
|
+
const nextNodes = nodes.map((node) => {
|
|
3626
|
+
if (updated || !isSsmlElement(node)) {
|
|
3627
|
+
return node;
|
|
3628
|
+
}
|
|
3629
|
+
if (predicate(node)) {
|
|
3630
|
+
updated = true;
|
|
3631
|
+
return update(node);
|
|
3632
|
+
}
|
|
3633
|
+
if (node.children) {
|
|
3634
|
+
const result = updateFirstElement(node.children, predicate, update);
|
|
3635
|
+
if (result.updated) {
|
|
3636
|
+
updated = true;
|
|
3637
|
+
return { ...node, children: result.nodes };
|
|
3638
|
+
}
|
|
3639
|
+
}
|
|
3640
|
+
return node;
|
|
3641
|
+
});
|
|
3642
|
+
return { nodes: nextNodes, updated };
|
|
3643
|
+
}
|
|
3644
|
+
function withChildren(document2, children) {
|
|
3645
|
+
const nextDocument = { ...document2, children };
|
|
3646
|
+
if (nextDocument.content !== void 0) {
|
|
3647
|
+
delete nextDocument.content;
|
|
3648
|
+
}
|
|
3649
|
+
return nextDocument;
|
|
3650
|
+
}
|
|
3651
|
+
function parseEditableText(value, lang) {
|
|
3652
|
+
try {
|
|
3653
|
+
const wrapper = buildSsml({
|
|
3654
|
+
version: "1.0",
|
|
3655
|
+
lang,
|
|
3656
|
+
children: []
|
|
3657
|
+
});
|
|
3658
|
+
const openingTagEnd = wrapper.indexOf(">") + 1;
|
|
3659
|
+
const children = parseSsml(`${wrapper.slice(0, openingTagEnd)}${value}</speak>`).children ?? [];
|
|
3660
|
+
return children.some(isSsmlElement) ? children : [value];
|
|
3661
|
+
} catch {
|
|
3662
|
+
return [value];
|
|
3663
|
+
}
|
|
3664
|
+
}
|
|
3665
|
+
function validateEditableText(value) {
|
|
3666
|
+
if (!value.includes("<")) {
|
|
3667
|
+
return null;
|
|
3668
|
+
}
|
|
3669
|
+
const source = `${EDITABLE_SSML_PREFIX}${value}${EDITABLE_SSML_SUFFIX}`;
|
|
3670
|
+
const validationError = validateSsml(source);
|
|
3671
|
+
if (!validationError) {
|
|
3672
|
+
return null;
|
|
3673
|
+
}
|
|
3674
|
+
return {
|
|
3675
|
+
message: validationError.message,
|
|
3676
|
+
offset: Math.min(Math.max(validationError.position - EDITABLE_SSML_PREFIX.length, 0), value.length)
|
|
3677
|
+
};
|
|
3678
|
+
}
|
|
3679
|
+
function serializeEditableText(nodes, lang) {
|
|
3680
|
+
if (nodes.length === 1 && typeof nodes[0] === "string") {
|
|
3681
|
+
return nodes[0];
|
|
3682
|
+
}
|
|
3683
|
+
const xml = buildSsml({
|
|
3684
|
+
version: "1.0",
|
|
3685
|
+
lang,
|
|
3686
|
+
children: nodes
|
|
3687
|
+
});
|
|
3688
|
+
const contentStart = xml.indexOf(">") + 1;
|
|
3689
|
+
return xml.slice(contentStart, -"</speak>".length);
|
|
3690
|
+
}
|
|
3691
|
+
function getEditableChildren(document2) {
|
|
3692
|
+
const children = getDocumentChildren2(document2);
|
|
3693
|
+
const element = findFirstElement(children, isProsody) ?? findFirstElement(children, isVoice);
|
|
3694
|
+
return element?.children ?? children;
|
|
3695
|
+
}
|
|
3696
|
+
function getEditableText(document2) {
|
|
3697
|
+
return serializeEditableText(getEditableChildren(document2), document2.lang);
|
|
3698
|
+
}
|
|
3699
|
+
function updateText(document2, value) {
|
|
3700
|
+
const nextChildren = parseEditableText(value, document2.lang);
|
|
3701
|
+
const editableChildren = nextChildren.length > 0 ? nextChildren : [value];
|
|
3702
|
+
const children = getDocumentChildren2(document2);
|
|
3703
|
+
const prosodyResult = updateFirstElement(children, isProsody, (prosody) => ({
|
|
3704
|
+
...prosody,
|
|
3705
|
+
children: editableChildren
|
|
3706
|
+
}));
|
|
3707
|
+
if (prosodyResult.updated) {
|
|
3708
|
+
return withChildren(document2, prosodyResult.nodes);
|
|
3709
|
+
}
|
|
3710
|
+
const voiceResult = updateFirstElement(children, isVoice, (voice) => ({
|
|
3711
|
+
...voice,
|
|
3712
|
+
children: editableChildren
|
|
3713
|
+
}));
|
|
3714
|
+
if (voiceResult.updated) {
|
|
3715
|
+
return withChildren(document2, voiceResult.nodes);
|
|
3716
|
+
}
|
|
3717
|
+
return withChildren(document2, editableChildren);
|
|
3718
|
+
}
|
|
3719
|
+
function getSelectionInfo(editor) {
|
|
3720
|
+
const model = editor.getModel();
|
|
3721
|
+
const selection = editor.getSelection();
|
|
3722
|
+
if (!model || !selection) {
|
|
3723
|
+
return {
|
|
3724
|
+
selectedText: "",
|
|
3725
|
+
characterCount: 0,
|
|
3726
|
+
hasSelection: false
|
|
3727
|
+
};
|
|
3728
|
+
}
|
|
3729
|
+
const selectedText = model.getValueInRange(selection);
|
|
3730
|
+
return {
|
|
3731
|
+
selectedText,
|
|
3732
|
+
characterCount: selectedText.length,
|
|
3733
|
+
hasSelection: selectedText.length > 0
|
|
3734
|
+
};
|
|
3735
|
+
}
|
|
3736
|
+
function getSelectionOverlayState(editor) {
|
|
3737
|
+
const info = getSelectionInfo(editor);
|
|
3738
|
+
if (!info.hasSelection) {
|
|
3739
|
+
return { ...info, position: null, placement: "above" };
|
|
3740
|
+
}
|
|
3741
|
+
const selection = editor.getSelection();
|
|
3742
|
+
if (!selection) {
|
|
3743
|
+
return { ...info, position: null, placement: "above" };
|
|
3744
|
+
}
|
|
3745
|
+
const position = editor.getScrolledVisiblePosition(selection.getStartPosition());
|
|
3746
|
+
if (!position) {
|
|
3747
|
+
return { ...info, position: null, placement: "above" };
|
|
3748
|
+
}
|
|
3749
|
+
const editorHeight = editor.getLayoutInfo().height;
|
|
3750
|
+
if (position.top + position.height < 0 || position.top > editorHeight) {
|
|
3751
|
+
return { ...info, position: null, placement: "above" };
|
|
3752
|
+
}
|
|
3753
|
+
return {
|
|
3754
|
+
...info,
|
|
3755
|
+
position,
|
|
3756
|
+
placement: position.top >= SELECTION_OVERLAY_ABOVE_THRESHOLD_LINES * position.height ? "above" : "below"
|
|
3757
|
+
};
|
|
3758
|
+
}
|
|
3759
|
+
function getCurrentDocument(document2, editor) {
|
|
3760
|
+
const value = editor?.getValue();
|
|
3761
|
+
return value === void 0 ? document2 : updateText(document2, value);
|
|
3762
|
+
}
|
|
3763
|
+
function getCurrentLineText(editor) {
|
|
3764
|
+
const model = editor.getModel();
|
|
3765
|
+
const selection = editor.getSelection();
|
|
3766
|
+
if (!model || !selection) {
|
|
3767
|
+
return null;
|
|
3768
|
+
}
|
|
3769
|
+
const text = model.getLineContent(selection.positionLineNumber);
|
|
3770
|
+
return text.trim().length > 0 ? text : null;
|
|
3771
|
+
}
|
|
3772
|
+
function getSelectedText(editor) {
|
|
3773
|
+
const model = editor.getModel();
|
|
3774
|
+
const selection = editor.getSelection();
|
|
3775
|
+
if (!model || !selection) {
|
|
3776
|
+
return null;
|
|
3777
|
+
}
|
|
3778
|
+
const selectedText = model.getValueInRange(selection);
|
|
3779
|
+
return selectedText.length > 0 ? selectedText : getCurrentLineText(editor);
|
|
3780
|
+
}
|
|
3781
|
+
function getSelectedSsml(editor, document2) {
|
|
3782
|
+
const selectedText = getSelectedText(editor);
|
|
3783
|
+
return selectedText === null ? null : buildPartialSsml(selectedText, getPartialContext(document2));
|
|
3784
|
+
}
|
|
3785
|
+
function getCurrentLineSsml(editor, document2) {
|
|
3786
|
+
const currentLineText = getCurrentLineText(editor);
|
|
3787
|
+
return currentLineText === null ? null : buildPartialSsml(currentLineText, getPartialContext(document2));
|
|
3788
|
+
}
|
|
3789
|
+
function acquireSsmlHoverProvider(monaco, locale) {
|
|
3790
|
+
const languages = monaco.languages;
|
|
3791
|
+
let registrations = hoverProviderRegistrations.get(languages);
|
|
3792
|
+
if (!registrations) {
|
|
3793
|
+
registrations = /* @__PURE__ */ new Map();
|
|
3794
|
+
hoverProviderRegistrations.set(languages, registrations);
|
|
3795
|
+
}
|
|
3796
|
+
let registration = registrations.get(locale);
|
|
3797
|
+
if (!registration) {
|
|
3798
|
+
const provider = {
|
|
3799
|
+
provideHover(model, position) {
|
|
3800
|
+
const target = findSsmlHoverTarget(model.getValue(), position.lineNumber, position.column);
|
|
3801
|
+
if (!target) {
|
|
3802
|
+
return void 0;
|
|
3803
|
+
}
|
|
3804
|
+
return {
|
|
3805
|
+
contents: [
|
|
3806
|
+
{
|
|
3807
|
+
isTrusted: false,
|
|
3808
|
+
supportHtml: false,
|
|
3809
|
+
value: formatSsmlHover(target, locale)
|
|
3810
|
+
}
|
|
3811
|
+
],
|
|
3812
|
+
range: target.range
|
|
3813
|
+
};
|
|
3814
|
+
}
|
|
3815
|
+
};
|
|
3816
|
+
const disposable = languages.registerHoverProvider("xml", {
|
|
3817
|
+
...provider
|
|
3818
|
+
});
|
|
3819
|
+
registration = { disposable, references: 0 };
|
|
3820
|
+
registrations.set(locale, registration);
|
|
3821
|
+
}
|
|
3822
|
+
registration.references += 1;
|
|
3823
|
+
let released = false;
|
|
3824
|
+
return () => {
|
|
3825
|
+
if (released) {
|
|
3826
|
+
return;
|
|
3827
|
+
}
|
|
3828
|
+
released = true;
|
|
3829
|
+
const currentRegistrations = hoverProviderRegistrations.get(languages);
|
|
3830
|
+
const current = currentRegistrations?.get(locale);
|
|
3831
|
+
if (!current) {
|
|
3832
|
+
return;
|
|
3833
|
+
}
|
|
3834
|
+
current.references -= 1;
|
|
3835
|
+
if (current.references === 0) {
|
|
3836
|
+
current.disposable.dispose();
|
|
3837
|
+
currentRegistrations?.delete(locale);
|
|
3838
|
+
if (currentRegistrations?.size === 0) {
|
|
3839
|
+
hoverProviderRegistrations.delete(languages);
|
|
3840
|
+
}
|
|
3841
|
+
}
|
|
3842
|
+
};
|
|
3843
|
+
}
|
|
3844
|
+
function applySsmlTemplate(editor, template) {
|
|
3845
|
+
const model = editor.getModel();
|
|
3846
|
+
const selection = editor.getSelection();
|
|
3847
|
+
if (!model || !selection) {
|
|
3848
|
+
return;
|
|
3849
|
+
}
|
|
3850
|
+
const startOffset = model.getOffsetAt(selection.getStartPosition());
|
|
3851
|
+
const endOffset = model.getOffsetAt(selection.getEndPosition());
|
|
3852
|
+
const { replacement, selectionOffset } = createSsmlInsertionEdit(model.getValue(), startOffset, endOffset, template);
|
|
3853
|
+
editor.pushUndoStop();
|
|
3854
|
+
const applied = editor.executeEdits("ssml-toolbar", [
|
|
3855
|
+
{
|
|
3856
|
+
range: selection,
|
|
3857
|
+
text: replacement
|
|
3858
|
+
}
|
|
3859
|
+
]);
|
|
3860
|
+
editor.pushUndoStop();
|
|
3861
|
+
if (!applied) {
|
|
3862
|
+
return;
|
|
3863
|
+
}
|
|
3864
|
+
const nextSelectionStart = model.getPositionAt(startOffset + selectionOffset);
|
|
3865
|
+
const nextSelectionEnd = model.getPositionAt(endOffset + selectionOffset);
|
|
3866
|
+
editor.setSelection({
|
|
3867
|
+
selectionStartLineNumber: nextSelectionStart.lineNumber,
|
|
3868
|
+
selectionStartColumn: nextSelectionStart.column,
|
|
3869
|
+
positionLineNumber: nextSelectionEnd.lineNumber,
|
|
3870
|
+
positionColumn: nextSelectionEnd.column
|
|
3871
|
+
});
|
|
3872
|
+
editor.focus();
|
|
3873
|
+
}
|
|
3874
|
+
function applySsmlInsertion(editor, insertion, option) {
|
|
3875
|
+
applySsmlTemplate(editor, insertion.createTemplate(option.value));
|
|
3876
|
+
}
|
|
3877
|
+
var SsmlEditor = (0, import_react.forwardRef)(function SsmlEditor2({
|
|
3878
|
+
document: document2,
|
|
3879
|
+
onChange,
|
|
3880
|
+
onSsmlChange,
|
|
3881
|
+
onSelectionChange,
|
|
3882
|
+
onPreviewSelection,
|
|
3883
|
+
language: languageProp,
|
|
3884
|
+
locale: localeProp,
|
|
3885
|
+
showToolbar = true,
|
|
3886
|
+
showToolbarIcons = true,
|
|
3887
|
+
showToolbarLabels = false,
|
|
3888
|
+
showDecorations = false,
|
|
3889
|
+
buttonVisibility,
|
|
3890
|
+
editorOptions,
|
|
3891
|
+
settings,
|
|
3892
|
+
height,
|
|
3893
|
+
minHeight,
|
|
3894
|
+
readOnly,
|
|
3895
|
+
theme,
|
|
3896
|
+
fontSize,
|
|
3897
|
+
wordWrap,
|
|
3898
|
+
lineNumbers,
|
|
3899
|
+
minimap,
|
|
3900
|
+
automaticLayout,
|
|
3901
|
+
toolbarOrder,
|
|
3902
|
+
toolbarGroups,
|
|
3903
|
+
insertionOrder,
|
|
3904
|
+
insertionGroups,
|
|
3905
|
+
customInsertions,
|
|
3906
|
+
additionalInsertions,
|
|
3907
|
+
emotionStyles,
|
|
3908
|
+
className,
|
|
3909
|
+
style,
|
|
3910
|
+
toolbarClassName,
|
|
3911
|
+
toolbarStyle,
|
|
3912
|
+
displayClassName,
|
|
3913
|
+
displayStyle,
|
|
3914
|
+
loadingFallback
|
|
3915
|
+
}, ref) {
|
|
3916
|
+
const resolvedEditorOptions = {
|
|
3917
|
+
...settings,
|
|
3918
|
+
...editorOptions,
|
|
3919
|
+
...height === void 0 ? {} : { height },
|
|
3920
|
+
...minHeight === void 0 ? {} : { minHeight },
|
|
3921
|
+
...readOnly === void 0 ? {} : { readOnly },
|
|
3922
|
+
...theme === void 0 ? {} : { theme },
|
|
3923
|
+
...fontSize === void 0 ? {} : { fontSize },
|
|
3924
|
+
...wordWrap === void 0 ? {} : { wordWrap },
|
|
3925
|
+
...lineNumbers === void 0 ? {} : { lineNumbers },
|
|
3926
|
+
...minimap === void 0 ? {} : { minimap },
|
|
3927
|
+
...automaticLayout === void 0 ? {} : { automaticLayout }
|
|
3928
|
+
};
|
|
3929
|
+
const helpPanelId = (0, import_react.useId)();
|
|
3930
|
+
const [draftDocument, setDraftDocument] = (0, import_react.useState)(document2);
|
|
3931
|
+
const draftDocumentRef = (0, import_react.useRef)(document2);
|
|
3932
|
+
const editorRef = (0, import_react.useRef)(null);
|
|
3933
|
+
const monacoRef = (0, import_react.useRef)(null);
|
|
3934
|
+
const releaseHoverProviderRef = (0, import_react.useRef)(null);
|
|
3935
|
+
const selectionChangeRef = (0, import_react.useRef)(null);
|
|
3936
|
+
const selectionLayoutDisposablesRef = (0, import_react.useRef)([]);
|
|
3937
|
+
const inlineDecorationIdsRef = (0, import_react.useRef)([]);
|
|
3938
|
+
const onSelectionChangeRef = (0, import_react.useRef)(onSelectionChange);
|
|
3939
|
+
const onPreviewSelectionRef = (0, import_react.useRef)(onPreviewSelection);
|
|
3940
|
+
const [selectionOverlay, setSelectionOverlay] = (0, import_react.useState)(EMPTY_SELECTION_OVERLAY);
|
|
3941
|
+
const [isDark, setIsDark] = (0, import_react.useState)(false);
|
|
3942
|
+
const [decorationsVisible, setDecorationsVisible] = (0, import_react.useState)(showDecorations);
|
|
3943
|
+
const [isHelpOpen, setIsHelpOpen] = (0, import_react.useState)(false);
|
|
3944
|
+
const [syntaxError, setSyntaxError] = (0, import_react.useState)(null);
|
|
3945
|
+
const language = localeProp ?? languageProp ?? DEFAULT_LOCALE;
|
|
3946
|
+
const languageRef = (0, import_react.useRef)(language);
|
|
3947
|
+
draftDocumentRef.current = draftDocument;
|
|
3948
|
+
languageRef.current = language;
|
|
3949
|
+
onSelectionChangeRef.current = onSelectionChange;
|
|
3950
|
+
onPreviewSelectionRef.current = onPreviewSelection;
|
|
3951
|
+
const copy = EDITOR_COPY[language];
|
|
3952
|
+
const showToolbarText = showToolbarLabels || !showToolbarIcons;
|
|
3953
|
+
const resolvedTheme = resolvedEditorOptions.theme ?? "system";
|
|
3954
|
+
const isDarkTheme = resolvedTheme === "dark" || resolvedTheme === "system" && isDark;
|
|
3955
|
+
const editorMinHeight = resolvedEditorOptions.minHeight ?? "8rem";
|
|
3956
|
+
const editorHeight = resolvedEditorOptions.height ?? editorMinHeight;
|
|
3957
|
+
const isReadOnly = resolvedEditorOptions.readOnly ?? false;
|
|
3958
|
+
const toolbarButtonStyle = showToolbarText ? styles.toolbarButton : { ...styles.toolbarButton, ...styles.toolbarIconOnly };
|
|
3959
|
+
const configuredInsertions = getConfiguredInsertions(emotionStyles, customInsertions, additionalInsertions);
|
|
3960
|
+
const visibleInsertions = orderInsertions(configuredInsertions, insertionOrder).filter(
|
|
3961
|
+
(insertion) => isSsmlEditorButtonVisible(buttonVisibility, insertion.id)
|
|
3962
|
+
);
|
|
3963
|
+
const insertionById = new Map(visibleInsertions.map((insertion) => [insertion.id, insertion]));
|
|
3964
|
+
const configuredInsertionGroups = insertionGroups ?? DEFAULT_INSERTION_GROUPS;
|
|
3965
|
+
const groupedInsertionIds = /* @__PURE__ */ new Set();
|
|
3966
|
+
const visibleInsertionGroups = configuredInsertionGroups.map((group) => {
|
|
3967
|
+
const groupInsertionIds = new Set(group.insertionIds);
|
|
3968
|
+
const candidates = insertionOrder && insertionOrder.length > 0 ? visibleInsertions.filter((insertion) => groupInsertionIds.has(insertion.id)) : group.insertionIds.map((id) => insertionById.get(id)).filter((insertion) => insertion !== void 0);
|
|
3969
|
+
const insertions = candidates.filter((insertion) => {
|
|
3970
|
+
if (groupedInsertionIds.has(insertion.id)) {
|
|
3971
|
+
return false;
|
|
3972
|
+
}
|
|
3973
|
+
groupedInsertionIds.add(insertion.id);
|
|
3974
|
+
return true;
|
|
3975
|
+
});
|
|
3976
|
+
return { group, insertions };
|
|
3977
|
+
}).filter(({ insertions }) => insertions.length > 0);
|
|
3978
|
+
const ungroupedInsertions = visibleInsertions.filter((insertion) => !groupedInsertionIds.has(insertion.id));
|
|
3979
|
+
const toolbarActionIds = ["undo", "redo", "clearAll", "format", "decorations", "help"];
|
|
3980
|
+
const defaultToolbarOrder = [
|
|
3981
|
+
"undo",
|
|
3982
|
+
"redo",
|
|
3983
|
+
...visibleInsertionGroups.flatMap(({ insertions }) => insertions.map((insertion) => insertion.id)),
|
|
3984
|
+
...ungroupedInsertions.map((insertion) => insertion.id),
|
|
3985
|
+
"clearAll",
|
|
3986
|
+
"format",
|
|
3987
|
+
"decorations",
|
|
3988
|
+
"help"
|
|
3989
|
+
];
|
|
3990
|
+
const visibleToolbarIds = /* @__PURE__ */ new Set([
|
|
3991
|
+
...visibleInsertions.map((insertion) => insertion.id),
|
|
3992
|
+
...toolbarActionIds.filter((id) => isSsmlEditorButtonVisible(buttonVisibility, id))
|
|
3993
|
+
]);
|
|
3994
|
+
const toolbarItemIds = orderToolbarButtons(
|
|
3995
|
+
defaultToolbarOrder.filter((id) => visibleToolbarIds.has(id)),
|
|
3996
|
+
toolbarOrder
|
|
3997
|
+
);
|
|
3998
|
+
const effectiveToolbarGroups = toolbarGroups ?? createDefaultToolbarGroups(configuredInsertionGroups);
|
|
3999
|
+
const toolbarGroupByButtonId = /* @__PURE__ */ new Map();
|
|
4000
|
+
for (const group of effectiveToolbarGroups) {
|
|
4001
|
+
for (const buttonId of group.buttonIds) {
|
|
4002
|
+
if (!toolbarGroupByButtonId.has(buttonId)) {
|
|
4003
|
+
toolbarGroupByButtonId.set(buttonId, group.id);
|
|
4004
|
+
}
|
|
4005
|
+
}
|
|
4006
|
+
}
|
|
4007
|
+
const helpInsertions = [
|
|
4008
|
+
...visibleInsertionGroups.flatMap(({ insertions }) => insertions),
|
|
4009
|
+
...ungroupedInsertions
|
|
4010
|
+
].filter(
|
|
4011
|
+
(insertion, index, insertions) => insertions.findIndex((candidate) => candidate.id === insertion.id) === index
|
|
4012
|
+
);
|
|
4013
|
+
const refreshSelectionOverlay = (editor, notify) => {
|
|
4014
|
+
const nextSelection = getSelectionOverlayState(editor);
|
|
4015
|
+
setSelectionOverlay(nextSelection);
|
|
4016
|
+
if (notify) {
|
|
4017
|
+
onSelectionChangeRef.current?.({
|
|
4018
|
+
selectedText: nextSelection.selectedText,
|
|
4019
|
+
characterCount: nextSelection.characterCount,
|
|
4020
|
+
hasSelection: nextSelection.hasSelection
|
|
4021
|
+
});
|
|
4022
|
+
}
|
|
4023
|
+
};
|
|
4024
|
+
(0, import_react.useEffect)(() => {
|
|
4025
|
+
injectEditorTheme();
|
|
4026
|
+
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
|
4027
|
+
setIsDark(mq.matches);
|
|
4028
|
+
const handler = (e) => setIsDark(e.matches);
|
|
4029
|
+
mq.addEventListener("change", handler);
|
|
4030
|
+
return () => mq.removeEventListener("change", handler);
|
|
4031
|
+
}, []);
|
|
4032
|
+
(0, import_react.useEffect)(() => {
|
|
4033
|
+
draftDocumentRef.current = document2;
|
|
4034
|
+
setDraftDocument(document2);
|
|
4035
|
+
}, [document2]);
|
|
4036
|
+
(0, import_react.useEffect)(() => {
|
|
4037
|
+
setDecorationsVisible(showDecorations);
|
|
4038
|
+
}, [showDecorations]);
|
|
4039
|
+
(0, import_react.useEffect)(() => {
|
|
4040
|
+
return () => {
|
|
4041
|
+
const model = editorRef.current?.getModel();
|
|
4042
|
+
if (model && monacoRef.current) {
|
|
4043
|
+
updateSsmlMarkers(monacoRef.current, model, model.getValue(), null);
|
|
4044
|
+
inlineDecorationIdsRef.current = clearSsmlInlineDecorations(model, inlineDecorationIdsRef.current);
|
|
4045
|
+
}
|
|
4046
|
+
selectionChangeRef.current?.dispose();
|
|
4047
|
+
selectionChangeRef.current = null;
|
|
4048
|
+
for (const disposable of selectionLayoutDisposablesRef.current) {
|
|
4049
|
+
disposable.dispose();
|
|
4050
|
+
}
|
|
4051
|
+
selectionLayoutDisposablesRef.current = [];
|
|
4052
|
+
releaseHoverProviderRef.current?.();
|
|
4053
|
+
releaseHoverProviderRef.current = null;
|
|
4054
|
+
editorRef.current = null;
|
|
4055
|
+
monacoRef.current = null;
|
|
4056
|
+
};
|
|
4057
|
+
}, []);
|
|
4058
|
+
(0, import_react.useEffect)(() => {
|
|
4059
|
+
const monaco = monacoRef.current;
|
|
4060
|
+
if (!monaco) {
|
|
4061
|
+
return;
|
|
4062
|
+
}
|
|
4063
|
+
releaseHoverProviderRef.current?.();
|
|
4064
|
+
releaseHoverProviderRef.current = acquireSsmlHoverProvider(monaco, language);
|
|
4065
|
+
}, [language]);
|
|
4066
|
+
const text = getEditableText(draftDocument);
|
|
4067
|
+
(0, import_react.useEffect)(() => {
|
|
4068
|
+
const nextSyntaxError = validateEditableText(text);
|
|
4069
|
+
setSyntaxError(nextSyntaxError);
|
|
4070
|
+
const model = editorRef.current?.getModel();
|
|
4071
|
+
if (model && monacoRef.current) {
|
|
4072
|
+
updateSsmlMarkers(monacoRef.current, model, text, nextSyntaxError);
|
|
4073
|
+
inlineDecorationIdsRef.current = syncSsmlInlineDecorations(
|
|
4074
|
+
model,
|
|
4075
|
+
text,
|
|
4076
|
+
language,
|
|
4077
|
+
decorationsVisible,
|
|
4078
|
+
inlineDecorationIdsRef.current
|
|
4079
|
+
);
|
|
4080
|
+
}
|
|
4081
|
+
}, [decorationsVisible, language, text]);
|
|
4082
|
+
const commit = (nextDocument) => {
|
|
4083
|
+
draftDocumentRef.current = nextDocument;
|
|
4084
|
+
setDraftDocument(nextDocument);
|
|
4085
|
+
onChange?.(nextDocument);
|
|
4086
|
+
onSsmlChange?.(buildSsml(nextDocument));
|
|
4087
|
+
};
|
|
4088
|
+
const canPreviewSelection = onPreviewSelection !== void 0;
|
|
4089
|
+
const previewSelection = () => {
|
|
4090
|
+
const editor = editorRef.current;
|
|
4091
|
+
if (!editor) {
|
|
4092
|
+
return;
|
|
4093
|
+
}
|
|
4094
|
+
const selectedSsml = getSelectedSsml(editor, draftDocumentRef.current);
|
|
4095
|
+
if (selectedSsml === null) {
|
|
4096
|
+
return;
|
|
4097
|
+
}
|
|
4098
|
+
onPreviewSelectionRef.current?.(selectedSsml);
|
|
4099
|
+
};
|
|
4100
|
+
(0, import_react.useImperativeHandle)(
|
|
4101
|
+
ref,
|
|
4102
|
+
() => ({
|
|
4103
|
+
getSelectedSsml: () => {
|
|
4104
|
+
const editor = editorRef.current;
|
|
4105
|
+
return editor ? getSelectedSsml(editor, draftDocumentRef.current) : null;
|
|
4106
|
+
},
|
|
4107
|
+
getCurrentLineSsml: () => {
|
|
4108
|
+
const editor = editorRef.current;
|
|
4109
|
+
return editor ? getCurrentLineSsml(editor, draftDocumentRef.current) : null;
|
|
4110
|
+
},
|
|
4111
|
+
getFullSsml: () => buildSsml(getCurrentDocument(draftDocumentRef.current, editorRef.current))
|
|
4112
|
+
}),
|
|
4113
|
+
[]
|
|
4114
|
+
);
|
|
4115
|
+
const renderInsertion = (insertion) => /* @__PURE__ */ React.createElement(
|
|
4116
|
+
ToolbarInsertionMenu,
|
|
4117
|
+
{
|
|
4118
|
+
key: insertion.id,
|
|
4119
|
+
insertion,
|
|
4120
|
+
language,
|
|
4121
|
+
isDarkTheme,
|
|
4122
|
+
showToolbarIcons,
|
|
4123
|
+
showToolbarText,
|
|
4124
|
+
toolbarButtonStyle,
|
|
4125
|
+
isReadOnly,
|
|
4126
|
+
onApply: (selectedInsertion, option) => {
|
|
4127
|
+
if (editorRef.current) {
|
|
4128
|
+
applySsmlInsertion(editorRef.current, selectedInsertion, option);
|
|
4129
|
+
}
|
|
4130
|
+
}
|
|
4131
|
+
}
|
|
4132
|
+
);
|
|
4133
|
+
const toolbarItemRenderers = /* @__PURE__ */ new Map([
|
|
4134
|
+
[
|
|
4135
|
+
"undo",
|
|
4136
|
+
() => /* @__PURE__ */ React.createElement(
|
|
4137
|
+
"button",
|
|
4138
|
+
{
|
|
4139
|
+
key: "undo",
|
|
4140
|
+
type: "button",
|
|
4141
|
+
style: toolbarButtonStyle,
|
|
4142
|
+
"aria-label": copy.undo,
|
|
4143
|
+
title: copy.undoTitle,
|
|
4144
|
+
disabled: isReadOnly,
|
|
4145
|
+
onClick: () => {
|
|
4146
|
+
if (!isReadOnly) {
|
|
4147
|
+
editorRef.current?.trigger("toolbar", "undo", null);
|
|
4148
|
+
editorRef.current?.focus();
|
|
4149
|
+
}
|
|
4150
|
+
}
|
|
4151
|
+
},
|
|
4152
|
+
showToolbarIcons && /* @__PURE__ */ React.createElement("span", { style: styles.toolbarIcon, "aria-hidden": "true" }, "\u21A9"),
|
|
4153
|
+
showToolbarText && /* @__PURE__ */ React.createElement("span", null, copy.undo)
|
|
4154
|
+
)
|
|
4155
|
+
],
|
|
4156
|
+
[
|
|
4157
|
+
"redo",
|
|
4158
|
+
() => /* @__PURE__ */ React.createElement(
|
|
4159
|
+
"button",
|
|
4160
|
+
{
|
|
4161
|
+
key: "redo",
|
|
4162
|
+
type: "button",
|
|
4163
|
+
style: toolbarButtonStyle,
|
|
4164
|
+
"aria-label": copy.redo,
|
|
4165
|
+
title: copy.redoTitle,
|
|
4166
|
+
disabled: isReadOnly,
|
|
4167
|
+
onClick: () => {
|
|
4168
|
+
if (!isReadOnly) {
|
|
4169
|
+
editorRef.current?.trigger("toolbar", "redo", null);
|
|
4170
|
+
editorRef.current?.focus();
|
|
4171
|
+
}
|
|
4172
|
+
}
|
|
4173
|
+
},
|
|
4174
|
+
showToolbarIcons && /* @__PURE__ */ React.createElement("span", { style: styles.toolbarIcon, "aria-hidden": "true" }, "\u21AA"),
|
|
4175
|
+
showToolbarText && /* @__PURE__ */ React.createElement("span", null, copy.redo)
|
|
4176
|
+
)
|
|
4177
|
+
],
|
|
4178
|
+
[
|
|
4179
|
+
"clearAll",
|
|
4180
|
+
() => /* @__PURE__ */ React.createElement(
|
|
4181
|
+
"button",
|
|
4182
|
+
{
|
|
4183
|
+
key: "clearAll",
|
|
4184
|
+
type: "button",
|
|
4185
|
+
style: toolbarButtonStyle,
|
|
4186
|
+
"aria-label": copy.clearAll,
|
|
4187
|
+
title: copy.clearAllTitle,
|
|
4188
|
+
disabled: isReadOnly,
|
|
4189
|
+
onClick: () => {
|
|
4190
|
+
if (!isReadOnly) {
|
|
4191
|
+
commit(clearSsmlDocument(draftDocument));
|
|
4192
|
+
}
|
|
4193
|
+
}
|
|
4194
|
+
},
|
|
4195
|
+
showToolbarIcons && /* @__PURE__ */ React.createElement("span", { style: styles.toolbarIcon, "aria-hidden": "true" }, "\xD7"),
|
|
4196
|
+
showToolbarText && /* @__PURE__ */ React.createElement("span", null, copy.clearAll)
|
|
4197
|
+
)
|
|
4198
|
+
],
|
|
4199
|
+
[
|
|
4200
|
+
"format",
|
|
4201
|
+
() => /* @__PURE__ */ React.createElement(
|
|
4202
|
+
"button",
|
|
4203
|
+
{
|
|
4204
|
+
key: "format",
|
|
4205
|
+
type: "button",
|
|
4206
|
+
style: toolbarButtonStyle,
|
|
4207
|
+
"aria-label": copy.format,
|
|
4208
|
+
title: copy.formatTitle,
|
|
4209
|
+
disabled: isReadOnly,
|
|
4210
|
+
onClick: () => {
|
|
4211
|
+
if (!isReadOnly) {
|
|
4212
|
+
const value = editorRef.current?.getValue() ?? getEditableText(draftDocument);
|
|
4213
|
+
commit(updateText(draftDocument, formatXmlFragment(value)));
|
|
4214
|
+
}
|
|
4215
|
+
}
|
|
4216
|
+
},
|
|
4217
|
+
showToolbarIcons && /* @__PURE__ */ React.createElement("span", { style: styles.toolbarIcon, "aria-hidden": "true" }, "\u2261"),
|
|
4218
|
+
showToolbarText && /* @__PURE__ */ React.createElement("span", null, copy.format)
|
|
4219
|
+
)
|
|
4220
|
+
],
|
|
4221
|
+
[
|
|
4222
|
+
"decorations",
|
|
4223
|
+
() => /* @__PURE__ */ React.createElement(
|
|
4224
|
+
ToolbarDecorationsSwitch,
|
|
4225
|
+
{
|
|
4226
|
+
key: "decorations",
|
|
4227
|
+
copy,
|
|
4228
|
+
showToolbarIcons,
|
|
4229
|
+
showToolbarText,
|
|
4230
|
+
decorationsVisible,
|
|
4231
|
+
onVisibilityChange: setDecorationsVisible
|
|
4232
|
+
}
|
|
4233
|
+
)
|
|
4234
|
+
],
|
|
4235
|
+
[
|
|
4236
|
+
"help",
|
|
4237
|
+
() => /* @__PURE__ */ React.createElement(
|
|
4238
|
+
"button",
|
|
4239
|
+
{
|
|
4240
|
+
key: "help",
|
|
4241
|
+
type: "button",
|
|
4242
|
+
style: toolbarButtonStyle,
|
|
4243
|
+
"aria-label": copy.help,
|
|
4244
|
+
title: copy.helpTitle,
|
|
4245
|
+
"aria-expanded": isHelpOpen,
|
|
4246
|
+
"aria-controls": helpPanelId,
|
|
4247
|
+
onClick: () => setIsHelpOpen((open) => !open)
|
|
4248
|
+
},
|
|
4249
|
+
showToolbarIcons && /* @__PURE__ */ React.createElement("span", { style: styles.toolbarIcon, "aria-hidden": "true" }, "?"),
|
|
4250
|
+
showToolbarText && /* @__PURE__ */ React.createElement("span", null, copy.help)
|
|
4251
|
+
)
|
|
4252
|
+
]
|
|
4253
|
+
]);
|
|
4254
|
+
for (const insertion of visibleInsertions) {
|
|
4255
|
+
toolbarItemRenderers.set(insertion.id, () => renderInsertion(insertion));
|
|
4256
|
+
}
|
|
4257
|
+
const renderToolbarItems = () => {
|
|
4258
|
+
let previousRenderedGroupId = UNGROUPED_TOOLBAR_GROUP;
|
|
4259
|
+
let hasRenderedToolbarItem = false;
|
|
4260
|
+
const renderedItems = [];
|
|
4261
|
+
for (const id of toolbarItemIds) {
|
|
4262
|
+
const render = toolbarItemRenderers.get(id);
|
|
4263
|
+
if (!render) {
|
|
4264
|
+
continue;
|
|
4265
|
+
}
|
|
4266
|
+
const groupId = toolbarGroupByButtonId.get(id) ?? UNGROUPED_TOOLBAR_GROUP;
|
|
4267
|
+
const showSeparator = hasRenderedToolbarItem && groupId !== previousRenderedGroupId;
|
|
4268
|
+
previousRenderedGroupId = groupId;
|
|
4269
|
+
hasRenderedToolbarItem = true;
|
|
4270
|
+
renderedItems.push(
|
|
4271
|
+
/* @__PURE__ */ React.createElement(import_react.Fragment, { key: id }, showSeparator && /* @__PURE__ */ React.createElement("span", { style: styles.toolbarSeparator, "aria-hidden": "true" }), render())
|
|
4272
|
+
);
|
|
4273
|
+
}
|
|
4274
|
+
return renderedItems;
|
|
4275
|
+
};
|
|
4276
|
+
return /* @__PURE__ */ React.createElement(
|
|
4277
|
+
"section",
|
|
4278
|
+
{
|
|
4279
|
+
className,
|
|
4280
|
+
style: { ...styles.container, ...style },
|
|
4281
|
+
"aria-label": copy.editorAriaLabel,
|
|
4282
|
+
"data-ssml-editor": "",
|
|
4283
|
+
"data-theme": isDarkTheme ? "dark" : "light"
|
|
4284
|
+
},
|
|
4285
|
+
showToolbar && /* @__PURE__ */ React.createElement(
|
|
4286
|
+
"div",
|
|
4287
|
+
{
|
|
4288
|
+
className: toolbarClassName,
|
|
4289
|
+
style: { ...styles.toolbarContainer, ...toolbarStyle },
|
|
4290
|
+
"data-ssml-editor-toolbar": ""
|
|
4291
|
+
},
|
|
4292
|
+
/* @__PURE__ */ React.createElement(
|
|
4293
|
+
"div",
|
|
4294
|
+
{
|
|
4295
|
+
style: styles.toolbarActions,
|
|
4296
|
+
role: "toolbar",
|
|
4297
|
+
"aria-label": copy.toolbarAriaLabel,
|
|
4298
|
+
"data-ssml-editor-toolbar-actions": ""
|
|
4299
|
+
},
|
|
4300
|
+
renderToolbarItems()
|
|
4301
|
+
)
|
|
4302
|
+
),
|
|
4303
|
+
/* @__PURE__ */ React.createElement("div", { className: displayClassName, style: { ...styles.display, ...displayStyle }, "data-ssml-editor-display": "" }, isHelpOpen && isSsmlEditorButtonVisible(buttonVisibility, "help") && /* @__PURE__ */ React.createElement("section", { id: helpPanelId, style: styles.helpPanel, "aria-label": copy.helpHeading }, /* @__PURE__ */ React.createElement("h3", { style: styles.helpHeading }, copy.helpHeading), /* @__PURE__ */ React.createElement("p", { style: styles.helpDescription }, copy.helpDescription), helpInsertions.length > 0 && /* @__PURE__ */ React.createElement("ul", { style: styles.helpList }, helpInsertions.map((insertion) => /* @__PURE__ */ React.createElement("li", { key: insertion.id, style: styles.helpItem }, /* @__PURE__ */ React.createElement("details", { className: "ssml-editor-help-settings-accordion", style: styles.helpSettingsAccordion }, /* @__PURE__ */ React.createElement("summary", { className: "ssml-editor-help-settings-summary", style: styles.helpSettingsSummary }, /* @__PURE__ */ React.createElement("span", { style: styles.helpIcon, "aria-hidden": "true" }, insertion.icon), /* @__PURE__ */ React.createElement("span", { style: styles.helpSettingsSummaryContent }, /* @__PURE__ */ React.createElement("strong", null, insertion.labels[language]), " ", insertion.tagName && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("code", null, `<${insertion.tagName}${insertion.selfClosing ? "/>" : ">"}`), " \u2014", " "), insertion.descriptions[language])), /* @__PURE__ */ React.createElement("p", { style: styles.helpSettingsDescription }, /* @__PURE__ */ React.createElement("strong", null, copy.parameters, ":"), " ", insertion.parameterDescription[language]), /* @__PURE__ */ React.createElement("ul", { style: styles.helpSettingsList }, insertion.options.map((option) => /* @__PURE__ */ React.createElement("li", { key: option.value }, /* @__PURE__ */ React.createElement("strong", null, option.labels[language]), option.descriptions && /* @__PURE__ */ React.createElement(React.Fragment, null, " \u2014 ", option.descriptions[language]))))))))), /* @__PURE__ */ React.createElement("div", { style: { ...styles.editor, minHeight: editorMinHeight } }, /* @__PURE__ */ React.createElement(
|
|
4304
|
+
import_react2.default,
|
|
4305
|
+
{
|
|
4306
|
+
height: editorHeight,
|
|
4307
|
+
language: "xml",
|
|
4308
|
+
theme: isDarkTheme ? "vs-dark" : "light",
|
|
4309
|
+
options: {
|
|
4310
|
+
automaticLayout: resolvedEditorOptions.automaticLayout ?? true,
|
|
4311
|
+
fontSize: resolvedEditorOptions.fontSize,
|
|
4312
|
+
hover: { enabled: "on" },
|
|
4313
|
+
inlayHints: { enabled: decorationsVisible ? "on" : "off" },
|
|
4314
|
+
lineNumbers: resolvedEditorOptions.lineNumbers,
|
|
4315
|
+
minimap: {
|
|
4316
|
+
enabled: resolvedEditorOptions.minimap ?? true
|
|
4317
|
+
},
|
|
4318
|
+
readOnly: isReadOnly,
|
|
4319
|
+
wordWrap: resolvedEditorOptions.wordWrap
|
|
4320
|
+
},
|
|
4321
|
+
value: text,
|
|
4322
|
+
loading: loadingFallback,
|
|
4323
|
+
onMount: (editor, monaco) => {
|
|
4324
|
+
editorRef.current = editor;
|
|
4325
|
+
monacoRef.current = monaco;
|
|
4326
|
+
selectionChangeRef.current?.dispose();
|
|
4327
|
+
selectionChangeRef.current = editor.onDidChangeCursorSelection(() => {
|
|
4328
|
+
refreshSelectionOverlay(editor, true);
|
|
4329
|
+
});
|
|
4330
|
+
for (const disposable of selectionLayoutDisposablesRef.current) {
|
|
4331
|
+
disposable.dispose();
|
|
4332
|
+
}
|
|
4333
|
+
selectionLayoutDisposablesRef.current = [
|
|
4334
|
+
editor.onDidScrollChange(() => refreshSelectionOverlay(editor, false)),
|
|
4335
|
+
editor.onDidLayoutChange(() => refreshSelectionOverlay(editor, false)),
|
|
4336
|
+
editor.onDidContentSizeChange(() => refreshSelectionOverlay(editor, false))
|
|
4337
|
+
];
|
|
4338
|
+
releaseHoverProviderRef.current?.();
|
|
4339
|
+
releaseHoverProviderRef.current = acquireSsmlHoverProvider(monaco, languageRef.current);
|
|
4340
|
+
const model = editor.getModel();
|
|
4341
|
+
const nextSyntaxError = validateEditableText(editor.getValue());
|
|
4342
|
+
setSyntaxError(nextSyntaxError);
|
|
4343
|
+
if (model) {
|
|
4344
|
+
updateSsmlMarkers(monaco, model, editor.getValue(), nextSyntaxError);
|
|
4345
|
+
inlineDecorationIdsRef.current = syncSsmlInlineDecorations(
|
|
4346
|
+
model,
|
|
4347
|
+
editor.getValue(),
|
|
4348
|
+
language,
|
|
4349
|
+
decorationsVisible,
|
|
4350
|
+
inlineDecorationIdsRef.current
|
|
4351
|
+
);
|
|
4352
|
+
}
|
|
4353
|
+
refreshSelectionOverlay(editor, true);
|
|
4354
|
+
},
|
|
4355
|
+
onChange: (value) => {
|
|
4356
|
+
commit(updateText(draftDocument, value ?? ""));
|
|
4357
|
+
if (editorRef.current) {
|
|
4358
|
+
refreshSelectionOverlay(editorRef.current, false);
|
|
4359
|
+
}
|
|
4360
|
+
}
|
|
4361
|
+
}
|
|
4362
|
+
), selectionOverlay.hasSelection && selectionOverlay.position && /* @__PURE__ */ React.createElement(
|
|
4363
|
+
"div",
|
|
4364
|
+
{
|
|
4365
|
+
role: "toolbar",
|
|
4366
|
+
"aria-label": copy.selectionActions,
|
|
4367
|
+
"data-ssml-editor-selection-actions": "",
|
|
4368
|
+
style: {
|
|
4369
|
+
...styles.selectionActions,
|
|
4370
|
+
top: selectionOverlay.position.top,
|
|
4371
|
+
left: selectionOverlay.position.left,
|
|
4372
|
+
transform: selectionOverlay.placement === "above" ? "translateY(calc(-100% - 0.5rem))" : `translateY(calc(${selectionOverlay.position.height}px + 0.5rem))`
|
|
4373
|
+
},
|
|
4374
|
+
onMouseDown: (event) => event.preventDefault()
|
|
4375
|
+
},
|
|
4376
|
+
/* @__PURE__ */ React.createElement("span", { style: styles.selectionCount, "aria-live": "polite" }, selectionOverlay.characterCount, copy.selectionCountSuffix),
|
|
4377
|
+
/* @__PURE__ */ React.createElement("span", { style: styles.selectionActionsDivider, "aria-hidden": "true" }),
|
|
4378
|
+
/* @__PURE__ */ React.createElement(
|
|
4379
|
+
"button",
|
|
4380
|
+
{
|
|
4381
|
+
type: "button",
|
|
4382
|
+
style: styles.selectionActionButton,
|
|
4383
|
+
title: copy.previewSelectionTitle,
|
|
4384
|
+
disabled: !canPreviewSelection,
|
|
4385
|
+
onClick: previewSelection
|
|
4386
|
+
},
|
|
4387
|
+
/* @__PURE__ */ React.createElement("span", { style: styles.selectionActionIcon, "aria-hidden": "true" }, "\u25B6"),
|
|
4388
|
+
copy.previewSelection
|
|
4389
|
+
)
|
|
4390
|
+
)), syntaxError && /* @__PURE__ */ React.createElement("p", { style: styles.error, role: "alert" }, copy.syntaxError, ": ", syntaxError.message))
|
|
4391
|
+
);
|
|
4392
|
+
});
|
|
4393
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
4394
|
+
0 && (module.exports = {
|
|
4395
|
+
EDITOR_COPY,
|
|
4396
|
+
INLINE_BADGE_COPY,
|
|
4397
|
+
SSML_HOVER_COPY,
|
|
4398
|
+
SSML_INSERTIONS,
|
|
4399
|
+
SsmlEditor,
|
|
4400
|
+
createSsmlEditorInsertionDefinition
|
|
4401
|
+
});
|
|
4402
|
+
//# sourceMappingURL=react.js.map
|