@codebit-programando-solucoes/codebit-web 1.1.17 → 1.1.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -24,6 +24,8 @@ var __webpack_require__ = {};
24
24
  var __webpack_exports__ = {};
25
25
  __webpack_require__.r(__webpack_exports__);
26
26
  __webpack_require__.d(__webpack_exports__, {
27
+ fetchImageAsBlob: ()=>fetchImageAsBlob,
28
+ getScrollbarWidth: ()=>getScrollbarWidth,
27
29
  loadImage: ()=>loadImage,
28
30
  markdownItBrEmptyLines: ()=>markdownItBrEmptyLines,
29
31
  ErrorCode: ()=>ErrorCode,
@@ -32,7 +34,7 @@ __webpack_require__.d(__webpack_exports__, {
32
34
  copyToClipboard: ()=>copyToClipboard,
33
35
  Api: ()=>Api,
34
36
  ApiError: ()=>ApiError,
35
- fetchImageAsBlob: ()=>fetchImageAsBlob
37
+ createAdvancedPartialRegex: ()=>createAdvancedPartialRegex
36
38
  });
37
39
  class ApiError extends Error {
38
40
  constructor(response, request = null){
@@ -287,6 +289,22 @@ const Api = {
287
289
  }
288
290
  }
289
291
  };
292
+ function createAdvancedPartialRegex(target, options = {}) {
293
+ const { matchFromEnd = true, caseInsensitive = false, allowMultipleSpaces = false } = options;
294
+ const escapeRegex = (char)=>char.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
295
+ let pattern = '';
296
+ for(let i = target.length - 1; i >= 0; i--){
297
+ const char = target[i];
298
+ if (' ' === char && allowMultipleSpaces) pattern = '' === pattern ? '\\s+' : '\\s+(?:' + pattern + ')?';
299
+ else {
300
+ const escapedChar = escapeRegex(char);
301
+ pattern = '' === pattern ? escapedChar + '?' : escapedChar + '(?:' + pattern + ')?';
302
+ }
303
+ }
304
+ if (matchFromEnd) pattern += '\\s*$';
305
+ const flags = caseInsensitive ? 'i' : '';
306
+ return new RegExp(pattern, flags);
307
+ }
290
308
  async function copyToClipboard(text) {
291
309
  if (navigator?.clipboard && globalThis.isSecureContext) {
292
310
  await navigator.clipboard.writeText(text);
@@ -390,13 +408,36 @@ const markdownItBrEmptyLines = (md)=>{
390
408
  }
391
409
  });
392
410
  };
411
+ function getScrollbarWidth(scrollbarWidth = 'auto') {
412
+ const outer = document.createElement('div');
413
+ outer.style.visibility = 'hidden';
414
+ outer.style.position = 'absolute';
415
+ outer.style.top = '-9999px';
416
+ outer.style.width = '100px';
417
+ outer.style.height = '100px';
418
+ outer.style.overflow = 'scroll';
419
+ outer.style.scrollbarWidth = 'thin';
420
+ const inner = document.createElement('div');
421
+ inner.style.width = '100%';
422
+ inner.style.height = '100%';
423
+ outer.appendChild(inner);
424
+ document.body.appendChild(outer);
425
+ const width = outer.offsetWidth - inner.offsetWidth;
426
+ outer.remove();
427
+ if (width > 0) return width;
428
+ if ('thin' === scrollbarWidth) return 8;
429
+ if ('none' === scrollbarWidth) return 0;
430
+ return 16;
431
+ }
393
432
  exports.Api = __webpack_exports__.Api;
394
433
  exports.ApiError = __webpack_exports__.ApiError;
395
434
  exports.ApiNetworkError = __webpack_exports__.ApiNetworkError;
396
435
  exports.ErrorCode = __webpack_exports__.ErrorCode;
397
436
  exports.Logger = __webpack_exports__.Logger;
398
437
  exports.copyToClipboard = __webpack_exports__.copyToClipboard;
438
+ exports.createAdvancedPartialRegex = __webpack_exports__.createAdvancedPartialRegex;
399
439
  exports.fetchImageAsBlob = __webpack_exports__.fetchImageAsBlob;
440
+ exports.getScrollbarWidth = __webpack_exports__.getScrollbarWidth;
400
441
  exports.loadImage = __webpack_exports__.loadImage;
401
442
  exports.markdownItBrEmptyLines = __webpack_exports__.markdownItBrEmptyLines;
402
443
  for(var __rspack_i in __webpack_exports__)if (-1 === [
@@ -406,7 +447,9 @@ for(var __rspack_i in __webpack_exports__)if (-1 === [
406
447
  "ErrorCode",
407
448
  "Logger",
408
449
  "copyToClipboard",
450
+ "createAdvancedPartialRegex",
409
451
  "fetchImageAsBlob",
452
+ "getScrollbarWidth",
410
453
  "loadImage",
411
454
  "markdownItBrEmptyLines"
412
455
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Options for creating an advanced partial regex pattern
3
+ */
4
+ export interface AdvancedPartialRegexOptions {
5
+ /**
6
+ * Whether to match from the end of the string (default: true)
7
+ */
8
+ matchFromEnd?: boolean;
9
+
10
+ /**
11
+ * Whether to perform case-insensitive matching (default: false)
12
+ */
13
+ caseInsensitive?: boolean;
14
+
15
+ /**
16
+ * Whether to allow multiple spaces to match a single space (default: false)
17
+ */
18
+ allowMultipleSpaces?: boolean;
19
+ }
20
+
21
+ /**
22
+ * Creates an advanced partial regex pattern that can match partial strings with flexible spacing.
23
+ *
24
+ * This function generates a regex pattern that can match partial strings with options for:
25
+ * - Matching from the end of the string
26
+ * - Case-insensitive matching
27
+ * - Allowing multiple spaces to match single spaces
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * // Create a regex that matches "hello world" with flexible spacing
32
+ * const regex = createAdvancedPartialRegex('hello world', { allowMultipleSpaces: true });
33
+ * console.log(regex.test('hello world')); // true
34
+ * console.log(regex.test('hello world')); // true
35
+ *
36
+ * // Create a case-insensitive regex
37
+ * const regex2 = createAdvancedPartialRegex('Hello', { caseInsensitive: true });
38
+ * console.log(regex2.test('hello')); // true
39
+ * ```
40
+ *
41
+ * @param target - The target string to create a partial regex for
42
+ * @param options - Configuration options for the regex generation
43
+ * @returns A RegExp object that matches partial strings according to the specified options
44
+ */
45
+ export function createAdvancedPartialRegex(
46
+ target: string,
47
+ options?: AdvancedPartialRegexOptions
48
+ ): RegExp;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Calculates the width of the browser's vertical scrollbar.
3
+ *
4
+ * The function creates temporary DOM elements, forces a scrollable container, and measures the difference between the outer container's width and the inner element's width. If the
5
+ * measurement fails (e.g., overlay scrollbars), a fallback value is returned based on the `scrollbarWidth` argument.
6
+ *
7
+ * @param {'auto' | 'none' | 'thin'} [scrollbarWidth='auto'] Desired fallback width when the actual scrollbar size cannot be measured. `'none'` returns **0px**, `'thin'` returns
8
+ * **8px**, and any other value (including `'auto'`) returns **16px**. Default is `'auto'`
9
+ * @returns {number} The width of the vertical scrollbar in pixels, or the fallback value when the measurement is not possible.
10
+ */
11
+ export function getScrollbarWidth(
12
+ scrollbarWidth?: 'auto' | 'none' | 'thin',
13
+ ): number;
@@ -1,4 +1,6 @@
1
+ export * from './AdvancedPartialRegex';
1
2
  export * from './Clipboard';
2
3
  export * from './Image';
3
4
  export * from './Logger';
4
5
  export * from './markdown-it';
6
+ export * from './Layout';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codebit-programando-solucoes/codebit-web",
3
- "version": "1.1.17",
3
+ "version": "1.1.19",
4
4
  "main": "./dist/index.cjs",
5
5
  "type": "module",
6
6
  "types": "./dist/index.d.ts",