@vunk/plus 1.11.8 → 1.11.9

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.
@@ -4172,6 +4172,84 @@ function _sfc_render$1(_ctx, _cache, $props, $setup, $data, $options) {
4172
4172
  }
4173
4173
  var ParagraphView = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["render", _sfc_render$1], ["__file", "/home/runner/work/vunk-plus/vunk-plus/packages/components/broadcasting-markdown/src/paragraph.vue"]]);
4174
4174
 
4175
+ function resolveSeparatorParagraphActions(options) {
4176
+ const {
4177
+ source,
4178
+ currentIndex,
4179
+ sortedSeparators,
4180
+ paragraphMinlength,
4181
+ lastParagraph
4182
+ } = options;
4183
+ const mergeActions = [];
4184
+ const appendActions = [];
4185
+ for (const separator of sortedSeparators) {
4186
+ const separatorLen = separator.length;
4187
+ const compareText = source.slice(
4188
+ currentIndex - separatorLen,
4189
+ currentIndex
4190
+ );
4191
+ if (compareText !== separator) {
4192
+ continue;
4193
+ }
4194
+ const start = lastParagraph?.end ?? 0;
4195
+ const end = currentIndex;
4196
+ const value = source.slice(start, end);
4197
+ if (lastParagraph && separator.length >= value.length) {
4198
+ if (lastParagraph.status === ParagraphStatus.initial) {
4199
+ mergeActions.push({
4200
+ end,
4201
+ value: source.slice(lastParagraph.start, end),
4202
+ separator
4203
+ });
4204
+ }
4205
+ continue;
4206
+ }
4207
+ if (value.length > paragraphMinlength) {
4208
+ appendActions.push({
4209
+ start,
4210
+ separator,
4211
+ end,
4212
+ status: ParagraphStatus.initial,
4213
+ value,
4214
+ broadcast: Broadcast.play
4215
+ });
4216
+ }
4217
+ }
4218
+ return {
4219
+ mergeActions,
4220
+ appendActions
4221
+ };
4222
+ }
4223
+ function resolveTailParagraphAction(options) {
4224
+ const { source, currentIndex, lastParagraph } = options;
4225
+ if (lastParagraph?.end === currentIndex) {
4226
+ return { type: "none" };
4227
+ }
4228
+ const start = lastParagraph?.end ?? 0;
4229
+ const end = currentIndex;
4230
+ if (lastParagraph && lastParagraph.status === ParagraphStatus.initial && lastParagraph.separator === "") {
4231
+ return {
4232
+ type: "merge",
4233
+ data: {
4234
+ end,
4235
+ value: source.slice(lastParagraph.start, end),
4236
+ separator: ""
4237
+ }
4238
+ };
4239
+ }
4240
+ return {
4241
+ type: "append",
4242
+ data: {
4243
+ start,
4244
+ separator: "",
4245
+ end,
4246
+ status: ParagraphStatus.initial,
4247
+ value: source.slice(start, end),
4248
+ broadcast: Broadcast.play
4249
+ }
4250
+ };
4251
+ }
4252
+
4175
4253
  var _sfc_main = defineComponent({
4176
4254
  name: "VkBroadcastingMarkdown",
4177
4255
  components: {
@@ -4226,9 +4304,6 @@ var _sfc_main = defineComponent({
4226
4304
  const isFinished = computed(() => {
4227
4305
  return currentIndex.value >= props2.source.length;
4228
4306
  });
4229
- const currentText = computed(() => {
4230
- return props2.source.substring(0, currentIndex.value);
4231
- });
4232
4307
  const fulfilledTextValue = computed(() => {
4233
4308
  if (props2.disabled) {
4234
4309
  return props2.source;
@@ -4250,41 +4325,24 @@ var _sfc_main = defineComponent({
4250
4325
  }, { immediate: true });
4251
4326
  function write() {
4252
4327
  const lastParagraph = theData.value.at(-1);
4253
- for (const separator of sortedSeparators.value) {
4254
- const separatorLen = separator.length;
4255
- const compareText = currentText.value.slice(
4256
- currentIndex.value - separatorLen,
4257
- currentIndex.value
4258
- );
4259
- if (compareText === separator) {
4260
- const start = lastParagraph?.end ?? 0;
4261
- const end = currentIndex.value;
4262
- const value = props2.source.slice(
4263
- start,
4264
- end
4265
- );
4266
- if (lastParagraph && separator.length >= value.length) {
4267
- if (lastParagraph.status === ParagraphStatus.initial) {
4268
- lastParagraph.end = end;
4269
- lastParagraph.value = props2.source.slice(
4270
- lastParagraph.start,
4271
- end
4272
- );
4273
- lastParagraph.separator = separator;
4274
- }
4275
- } else if (value.length > props2.paragraphMinlength) {
4276
- const paragraph = {
4277
- start,
4278
- separator,
4279
- end,
4280
- status: ParagraphStatus.initial,
4281
- value,
4282
- broadcast: Broadcast.play
4283
- };
4284
- addParagraph(paragraph);
4285
- }
4328
+ const separatorActions = resolveSeparatorParagraphActions({
4329
+ source: props2.source,
4330
+ currentIndex: currentIndex.value,
4331
+ sortedSeparators: sortedSeparators.value,
4332
+ paragraphMinlength: props2.paragraphMinlength,
4333
+ lastParagraph
4334
+ });
4335
+ separatorActions.mergeActions.forEach((action) => {
4336
+ if (!lastParagraph) {
4337
+ return;
4286
4338
  }
4287
- }
4339
+ lastParagraph.end = action.end;
4340
+ lastParagraph.value = action.value;
4341
+ lastParagraph.separator = action.separator;
4342
+ });
4343
+ separatorActions.appendActions.forEach((action) => {
4344
+ addParagraph(action);
4345
+ });
4288
4346
  if (currentIndex.value < props2.source.length) {
4289
4347
  currentIndex.value++;
4290
4348
  setTimeout(write, props2.delay);
@@ -4293,30 +4351,24 @@ var _sfc_main = defineComponent({
4293
4351
  setTimeout(write, props2.delay);
4294
4352
  return;
4295
4353
  }
4296
- if (lastParagraph?.end === currentIndex.value) {
4354
+ const tailAction = resolveTailParagraphAction({
4355
+ source: props2.source,
4356
+ currentIndex: currentIndex.value,
4357
+ lastParagraph
4358
+ });
4359
+ if (tailAction.type === "none") {
4297
4360
  return;
4298
4361
  }
4299
- const start = lastParagraph?.end ?? 0;
4300
- const end = currentIndex.value;
4301
- const value = props2.source.slice(start, end);
4302
- if (lastParagraph && lastParagraph.status === ParagraphStatus.initial && lastParagraph.separator === "") {
4303
- lastParagraph.end = end;
4304
- lastParagraph.value = props2.source.slice(
4305
- lastParagraph.start,
4306
- end
4307
- );
4308
- lastParagraph.separator = "";
4309
- } else {
4310
- const paragraph = {
4311
- start,
4312
- separator: "",
4313
- end,
4314
- status: ParagraphStatus.initial,
4315
- value,
4316
- broadcast: Broadcast.play
4317
- };
4318
- addParagraph(paragraph);
4362
+ if (tailAction.type === "merge") {
4363
+ if (!lastParagraph) {
4364
+ return;
4365
+ }
4366
+ lastParagraph.end = tailAction.data.end;
4367
+ lastParagraph.value = tailAction.data.value;
4368
+ lastParagraph.separator = tailAction.data.separator;
4369
+ return;
4319
4370
  }
4371
+ addParagraph(tailAction.data);
4320
4372
  }
4321
4373
  }
4322
4374
  function isPrevParagraphFulfilled(currentIndex2) {
@@ -179,10 +179,10 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
179
179
  processing: (paragraph: Paragraph) => void;
180
180
  delay: number;
181
181
  status: TickerStatus;
182
+ paragraphMinlength: number;
182
183
  separators: string[];
183
184
  keepRead: boolean;
184
185
  textToSpeech: import("./types").TextToSpeech;
185
- paragraphMinlength: number;
186
186
  }, {}, {
187
187
  ParagraphView: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
188
188
  enable: {
@@ -0,0 +1,29 @@
1
+ import type { Paragraph } from './types';
2
+ interface SeparatorActionOptions {
3
+ source: string;
4
+ currentIndex: number;
5
+ sortedSeparators: string[];
6
+ paragraphMinlength: number;
7
+ lastParagraph?: Paragraph;
8
+ }
9
+ interface TailActionOptions {
10
+ source: string;
11
+ currentIndex: number;
12
+ lastParagraph?: Paragraph;
13
+ }
14
+ export interface ParagraphSeparatorActions {
15
+ mergeActions: Array<Pick<Paragraph, 'end' | 'value' | 'separator'>>;
16
+ appendActions: Array<Pick<Paragraph, 'start' | 'separator' | 'end' | 'status' | 'value' | 'broadcast'>>;
17
+ }
18
+ export type TailParagraphAction = {
19
+ type: 'none';
20
+ } | {
21
+ type: 'merge';
22
+ data: Pick<Paragraph, 'end' | 'value' | 'separator'>;
23
+ } | {
24
+ type: 'append';
25
+ data: Pick<Paragraph, 'start' | 'separator' | 'end' | 'status' | 'value' | 'broadcast'>;
26
+ };
27
+ export declare function resolveSeparatorParagraphActions(options: SeparatorActionOptions): ParagraphSeparatorActions;
28
+ export declare function resolveTailParagraphAction(options: TailActionOptions): TailParagraphAction;
29
+ export {};
@@ -262,10 +262,10 @@ declare const _default: import("vue").DefineComponent<import("vue").ExtractPropT
262
262
  processing: (paragraph: __VkBroadcastingMarkdown.Paragraph) => void;
263
263
  delay: number;
264
264
  status: TickerStatus;
265
+ paragraphMinlength: number;
265
266
  separators: string[];
266
267
  keepRead: boolean;
267
268
  textToSpeech: __VkBroadcastingMarkdown.TextToSpeech;
268
- paragraphMinlength: number;
269
269
  }, {}, {
270
270
  ParagraphView: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
271
271
  enable: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vunk/plus",
3
- "version": "1.11.8",
3
+ "version": "1.11.9",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "license": "ISC",