visualfries 0.1.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 +213 -0
- package/dist/DIContainer.d.ts +4 -0
- package/dist/DIContainer.js +145 -0
- package/dist/SceneBuilder.svelte.d.ts +8574 -0
- package/dist/SceneBuilder.svelte.js +409 -0
- package/dist/adapters/subtitleHelpers.d.ts +2 -0
- package/dist/adapters/subtitleHelpers.js +187 -0
- package/dist/animations/AnimationContext.d.ts +17 -0
- package/dist/animations/AnimationContext.js +72 -0
- package/dist/animations/AnimationPresetsRegister.d.ts +362 -0
- package/dist/animations/AnimationPresetsRegister.js +20 -0
- package/dist/animations/AnimationSetup.d.ts +8 -0
- package/dist/animations/AnimationSetup.js +30 -0
- package/dist/animations/SplitTextCache.d.ts +28 -0
- package/dist/animations/SplitTextCache.js +68 -0
- package/dist/animations/animationBuilder.d.ts +31 -0
- package/dist/animations/animationBuilder.js +255 -0
- package/dist/animations/animationPreset.d.ts +7 -0
- package/dist/animations/animationPreset.js +31 -0
- package/dist/animations/builders/AnimationPresetFactory.d.ts +43 -0
- package/dist/animations/builders/AnimationPresetFactory.js +139 -0
- package/dist/animations/builders/LineHighlighterAnimationBuilder.d.ts +16 -0
- package/dist/animations/builders/LineHighlighterAnimationBuilder.js +183 -0
- package/dist/animations/builders/WordHighlighterAnimationBuilder.d.ts +15 -0
- package/dist/animations/builders/WordHighlighterAnimationBuilder.js +180 -0
- package/dist/animations/engines/AnimationEngineAdaptor.d.ts +107 -0
- package/dist/animations/engines/AnimationEngineAdaptor.js +1 -0
- package/dist/animations/engines/GSAPEngineAdaptor.d.ts +21 -0
- package/dist/animations/engines/GSAPEngineAdaptor.js +145 -0
- package/dist/animations/presets/index.d.ts +2 -0
- package/dist/animations/presets/index.js +3 -0
- package/dist/animations/presets/lines.d.ts +52 -0
- package/dist/animations/presets/lines.js +547 -0
- package/dist/animations/presets/words.d.ts +31 -0
- package/dist/animations/presets/words.js +268 -0
- package/dist/animations/transformers/AnimationReferenceTransformer.d.ts +9 -0
- package/dist/animations/transformers/AnimationReferenceTransformer.js +114 -0
- package/dist/builders/PixiComponentBuilder.d.ts +63 -0
- package/dist/builders/PixiComponentBuilder.js +112 -0
- package/dist/builders/_ComponentState.svelte.d.ts +795 -0
- package/dist/builders/_ComponentState.svelte.js +203 -0
- package/dist/builders/html/HtmlBuilder.d.ts +66 -0
- package/dist/builders/html/HtmlBuilder.js +171 -0
- package/dist/builders/html/HtmlBuilderFactory.d.ts +27 -0
- package/dist/builders/html/HtmlBuilderFactory.js +30 -0
- package/dist/builders/html/StyleBuilder.d.ts +13 -0
- package/dist/builders/html/StyleBuilder.js +133 -0
- package/dist/builders/html/StyleProcessor.d.ts +9 -0
- package/dist/builders/html/StyleProcessor.js +1 -0
- package/dist/builders/html/TextComponentHtmlBuilder.d.ts +16 -0
- package/dist/builders/html/TextComponentHtmlBuilder.js +93 -0
- package/dist/builders/html/TextShadowBuilder.d.ts +60 -0
- package/dist/builders/html/TextShadowBuilder.js +227 -0
- package/dist/builders/html/processors/AppearanceStyleProcessor.d.ts +5 -0
- package/dist/builders/html/processors/AppearanceStyleProcessor.js +57 -0
- package/dist/builders/html/processors/TextAppearanceStyleProcessor.d.ts +5 -0
- package/dist/builders/html/processors/TextAppearanceStyleProcessor.js +37 -0
- package/dist/builders/html/processors/TextEffectsStyleProcessor.d.ts +6 -0
- package/dist/builders/html/processors/TextEffectsStyleProcessor.js +68 -0
- package/dist/commands/Command.d.ts +6 -0
- package/dist/commands/Command.js +1 -0
- package/dist/commands/CommandRunner.d.ts +28 -0
- package/dist/commands/CommandRunner.js +81 -0
- package/dist/commands/CommandTypes.d.ts +11 -0
- package/dist/commands/CommandTypes.js +13 -0
- package/dist/commands/PauseCommand.d.ts +4 -0
- package/dist/commands/PauseCommand.js +5 -0
- package/dist/commands/PlayCommand.d.ts +4 -0
- package/dist/commands/PlayCommand.js +6 -0
- package/dist/commands/RenderCommand.d.ts +15 -0
- package/dist/commands/RenderCommand.js +18 -0
- package/dist/commands/RenderFrameCommand.d.ts +17 -0
- package/dist/commands/RenderFrameCommand.js +93 -0
- package/dist/commands/ReplaceSourceOnTimeCommand.d.ts +4 -0
- package/dist/commands/ReplaceSourceOnTimeCommand.js +22 -0
- package/dist/commands/SeekCommand.d.ts +15 -0
- package/dist/commands/SeekCommand.js +39 -0
- package/dist/commands/UpdateComponentCommand.d.ts +4 -0
- package/dist/commands/UpdateComponentCommand.js +17 -0
- package/dist/components/AnimatedGIF.d.ts +201 -0
- package/dist/components/AnimatedGIF.js +391 -0
- package/dist/components/Component.svelte.d.ts +33 -0
- package/dist/components/Component.svelte.js +152 -0
- package/dist/components/ComponentContext.svelte.d.ts +33 -0
- package/dist/components/ComponentContext.svelte.js +105 -0
- package/dist/components/hooks/AnimationHook.d.ts +25 -0
- package/dist/components/hooks/AnimationHook.js +180 -0
- package/dist/components/hooks/CanvasShapeHook.d.ts +12 -0
- package/dist/components/hooks/CanvasShapeHook.js +229 -0
- package/dist/components/hooks/HtmlAnimationHook.d.ts +8 -0
- package/dist/components/hooks/HtmlAnimationHook.js +70 -0
- package/dist/components/hooks/HtmlTextHook.d.ts +16 -0
- package/dist/components/hooks/HtmlTextHook.js +102 -0
- package/dist/components/hooks/HtmlToCanvasHook.d.ts +16 -0
- package/dist/components/hooks/HtmlToCanvasHook.js +148 -0
- package/dist/components/hooks/ImageHook.d.ts +10 -0
- package/dist/components/hooks/ImageHook.js +45 -0
- package/dist/components/hooks/MediaHook.d.ts +15 -0
- package/dist/components/hooks/MediaHook.js +252 -0
- package/dist/components/hooks/MediaSeekingHook.d.ts +12 -0
- package/dist/components/hooks/MediaSeekingHook.js +204 -0
- package/dist/components/hooks/PixiDisplayObjectHook.d.ts +15 -0
- package/dist/components/hooks/PixiDisplayObjectHook.js +77 -0
- package/dist/components/hooks/PixiGifHook.d.ts +15 -0
- package/dist/components/hooks/PixiGifHook.js +97 -0
- package/dist/components/hooks/PixiProgressShapeHook.d.ts +12 -0
- package/dist/components/hooks/PixiProgressShapeHook.js +128 -0
- package/dist/components/hooks/PixiSplitScreenDisplayObjectHook.d.ts +21 -0
- package/dist/components/hooks/PixiSplitScreenDisplayObjectHook.js +210 -0
- package/dist/components/hooks/PixiTextureHook.d.ts +7 -0
- package/dist/components/hooks/PixiTextureHook.js +29 -0
- package/dist/components/hooks/PixiVideoTextureHook.d.ts +10 -0
- package/dist/components/hooks/PixiVideoTextureHook.js +35 -0
- package/dist/components/hooks/SubtitlesHook.d.ts +88 -0
- package/dist/components/hooks/SubtitlesHook.js +199 -0
- package/dist/components/hooks/VerifyGifHook.d.ts +7 -0
- package/dist/components/hooks/VerifyGifHook.js +27 -0
- package/dist/components/hooks/VerifyImageHook.d.ts +7 -0
- package/dist/components/hooks/VerifyImageHook.js +27 -0
- package/dist/components/hooks/VerifyMediaHook.d.ts +7 -0
- package/dist/components/hooks/VerifyMediaHook.js +21 -0
- package/dist/components/hooks/shapes/progress/CustomProgressRenderer.d.ts +8 -0
- package/dist/components/hooks/shapes/progress/CustomProgressRenderer.js +53 -0
- package/dist/components/hooks/shapes/progress/DoubleProgressRenderer.d.ts +8 -0
- package/dist/components/hooks/shapes/progress/DoubleProgressRenderer.js +69 -0
- package/dist/components/hooks/shapes/progress/LinearProgressRenderer.d.ts +8 -0
- package/dist/components/hooks/shapes/progress/LinearProgressRenderer.js +60 -0
- package/dist/components/hooks/shapes/progress/PerimeterProgressRenderer.d.ts +9 -0
- package/dist/components/hooks/shapes/progress/PerimeterProgressRenderer.js +213 -0
- package/dist/components/hooks/shapes/progress/ProgressRenderer.d.ts +17 -0
- package/dist/components/hooks/shapes/progress/ProgressRenderer.js +75 -0
- package/dist/components/hooks/shapes/progress/RadialProgressRenderer.d.ts +8 -0
- package/dist/components/hooks/shapes/progress/RadialProgressRenderer.js +50 -0
- package/dist/components/hooks/shapes/progress/index.d.ts +6 -0
- package/dist/components/hooks/shapes/progress/index.js +6 -0
- package/dist/composers/componentComposer.d.ts +55 -0
- package/dist/composers/componentComposer.js +118 -0
- package/dist/composers/layerComposer.d.ts +46 -0
- package/dist/composers/layerComposer.js +79 -0
- package/dist/composers/sceneComposer.d.ts +48 -0
- package/dist/composers/sceneComposer.js +92 -0
- package/dist/constants.d.ts +12 -0
- package/dist/constants.js +14 -0
- package/dist/directors/ComponentDirector.d.ts +20 -0
- package/dist/directors/ComponentDirector.js +86 -0
- package/dist/factories/SceneBuilderFactory.d.ts +15 -0
- package/dist/factories/SceneBuilderFactory.js +51 -0
- package/dist/fonts/GoogleFontsProvider.d.ts +12 -0
- package/dist/fonts/GoogleFontsProvider.js +125 -0
- package/dist/fonts/fontLoader.d.ts +15 -0
- package/dist/fonts/fontLoader.js +41 -0
- package/dist/fonts/types.d.ts +1 -0
- package/dist/fonts/types.js +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +14 -0
- package/dist/layers/Layer.svelte.d.ts +8492 -0
- package/dist/layers/Layer.svelte.js +125 -0
- package/dist/managers/AppManager.svelte.d.ts +23 -0
- package/dist/managers/AppManager.svelte.js +89 -0
- package/dist/managers/ComponentsManager.svelte.d.ts +49 -0
- package/dist/managers/ComponentsManager.svelte.js +247 -0
- package/dist/managers/DomManager.d.ts +18 -0
- package/dist/managers/DomManager.js +73 -0
- package/dist/managers/EventManager.d.ts +7 -0
- package/dist/managers/EventManager.js +22 -0
- package/dist/managers/LayersManager.svelte.d.ts +8499 -0
- package/dist/managers/LayersManager.svelte.js +176 -0
- package/dist/managers/MediaManager.d.ts +32 -0
- package/dist/managers/MediaManager.js +243 -0
- package/dist/managers/RenderManager.d.ts +23 -0
- package/dist/managers/RenderManager.js +59 -0
- package/dist/managers/StateManager.svelte.d.ts +8746 -0
- package/dist/managers/StateManager.svelte.js +272 -0
- package/dist/managers/SubtitlesManager.svelte.d.ts +261 -0
- package/dist/managers/SubtitlesManager.svelte.js +1385 -0
- package/dist/managers/TimeManager.svelte.d.ts +6 -0
- package/dist/managers/TimeManager.svelte.js +18 -0
- package/dist/managers/TimelineManager.svelte.d.ts +25 -0
- package/dist/managers/TimelineManager.svelte.js +152 -0
- package/dist/registers.d.ts +12 -0
- package/dist/registers.js +29 -0
- package/dist/schemas/runtime/index.d.ts +3 -0
- package/dist/schemas/runtime/index.js +4 -0
- package/dist/schemas/runtime/types.d.ts +323 -0
- package/dist/schemas/runtime/types.js +12 -0
- package/dist/schemas/scene/animations.d.ts +89738 -0
- package/dist/schemas/scene/animations.js +211 -0
- package/dist/schemas/scene/components.js +515 -0
- package/dist/schemas/scene/core.js +160 -0
- package/dist/schemas/scene/index.d.ts +22 -0
- package/dist/schemas/scene/index.js +10 -0
- package/dist/schemas/scene/properties.d.ts +914 -0
- package/dist/schemas/scene/properties.js +398 -0
- package/dist/schemas/scene/subtitles.d.ts +1141 -0
- package/dist/schemas/scene/subtitles.js +111 -0
- package/dist/schemas/scene/utils.d.ts +1 -0
- package/dist/schemas/scene/utils.js +5 -0
- package/dist/seeds/SeedFactory.d.ts +59 -0
- package/dist/seeds/SeedFactory.js +99 -0
- package/dist/seeds/index.d.ts +8 -0
- package/dist/seeds/index.js +8 -0
- package/dist/transformers/ColorTransformer.d.ts +5 -0
- package/dist/transformers/ColorTransformer.js +67 -0
- package/dist/transformers/PixiColorTransformer.d.ts +22 -0
- package/dist/transformers/PixiColorTransformer.js +104 -0
- package/dist/utils/canvas.d.ts +6 -0
- package/dist/utils/canvas.js +18 -0
- package/dist/utils/document.d.ts +2 -0
- package/dist/utils/document.js +36 -0
- package/dist/utils/emoji.d.ts +10 -0
- package/dist/utils/emoji.js +51 -0
- package/dist/utils/html.d.ts +4 -0
- package/dist/utils/html.js +45 -0
- package/dist/utils/svgGenerator.d.ts +20 -0
- package/dist/utils/svgGenerator.js +103 -0
- package/dist/utils/utils.d.ts +5 -0
- package/dist/utils/utils.js +125 -0
- package/package.json +96 -0
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { ColorTypeShape } from './properties.js';
|
|
3
|
+
// ============================================================================
|
|
4
|
+
// COMPACT WORD FORMAT SCHEMAS
|
|
5
|
+
// ============================================================================
|
|
6
|
+
/**
|
|
7
|
+
* Compact word metadata object with optional short keys
|
|
8
|
+
*/
|
|
9
|
+
const CompactWordMetadataShape = z
|
|
10
|
+
.object({
|
|
11
|
+
s: z.number().optional(), // size override in percent
|
|
12
|
+
si: z.number().optional(), // speaker index
|
|
13
|
+
c: ColorTypeShape.optional(), // color (0-1)
|
|
14
|
+
e: z.string().optional(), // emoji
|
|
15
|
+
w: z.string().optional(), // font weight or bold, bolder etc.
|
|
16
|
+
f: z.string().optional() // font family
|
|
17
|
+
})
|
|
18
|
+
.catchall(z.any())
|
|
19
|
+
.optional(); // Allow additional metadata fields
|
|
20
|
+
/**
|
|
21
|
+
* Compact word tuple: [text, start_at, end_at, metadata?]
|
|
22
|
+
*/
|
|
23
|
+
const CompactWordTupleShape = z
|
|
24
|
+
.tuple([
|
|
25
|
+
z.string(), // text
|
|
26
|
+
z.number(), // start_at
|
|
27
|
+
z.number() // end_at
|
|
28
|
+
])
|
|
29
|
+
.rest(z.union([CompactWordMetadataShape, z.null()])); // optional metadata as 4th element, can be null
|
|
30
|
+
// ============================================================================
|
|
31
|
+
// REGULAR WORD FORMAT SCHEMAS
|
|
32
|
+
// ============================================================================
|
|
33
|
+
/**
|
|
34
|
+
* Regular word object with full property names
|
|
35
|
+
*/
|
|
36
|
+
const SubtitleWordShape = z.object({
|
|
37
|
+
id: z.string(),
|
|
38
|
+
start_at: z.number(),
|
|
39
|
+
end_at: z.number(),
|
|
40
|
+
text: z.string(),
|
|
41
|
+
position: z.number().optional()
|
|
42
|
+
});
|
|
43
|
+
// ============================================================================
|
|
44
|
+
// SUBTITLE SCHEMAS
|
|
45
|
+
// ============================================================================
|
|
46
|
+
const EnlargeShape = z
|
|
47
|
+
.union([
|
|
48
|
+
z.boolean(),
|
|
49
|
+
z.number(),
|
|
50
|
+
z.string().transform((val) => {
|
|
51
|
+
const num = parseFloat(val);
|
|
52
|
+
if (isNaN(num)) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return num;
|
|
56
|
+
})
|
|
57
|
+
])
|
|
58
|
+
.optional()
|
|
59
|
+
.transform((v) => {
|
|
60
|
+
if (typeof v === 'boolean') {
|
|
61
|
+
return v ? 150 : undefined;
|
|
62
|
+
}
|
|
63
|
+
return v;
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Subtitle with compact words format
|
|
67
|
+
*/
|
|
68
|
+
const SubtitleWithCompactWordsShape = z.object({
|
|
69
|
+
id: z.string(),
|
|
70
|
+
start_at: z.number(),
|
|
71
|
+
end_at: z.number(),
|
|
72
|
+
text: z.string(),
|
|
73
|
+
words: z.array(CompactWordTupleShape).optional(),
|
|
74
|
+
// Optional appearance fields
|
|
75
|
+
enlarge: EnlargeShape.optional(),
|
|
76
|
+
visible: z.boolean().optional(),
|
|
77
|
+
emoji: z.string().optional(),
|
|
78
|
+
color: ColorTypeShape.optional(),
|
|
79
|
+
background: ColorTypeShape.optional()
|
|
80
|
+
});
|
|
81
|
+
/**
|
|
82
|
+
* Subtitle with regular words format (legacy)
|
|
83
|
+
*/
|
|
84
|
+
const SubtitleWithLegacyWordsShape = z.object({
|
|
85
|
+
id: z.string(),
|
|
86
|
+
start_at: z.number(),
|
|
87
|
+
end_at: z.number(),
|
|
88
|
+
text: z.string(),
|
|
89
|
+
words: z.array(SubtitleWordShape).optional(),
|
|
90
|
+
// Optional appearance fields
|
|
91
|
+
enlarge: EnlargeShape.optional(),
|
|
92
|
+
visible: z.boolean().optional(),
|
|
93
|
+
emoji: z.string().optional(),
|
|
94
|
+
color: z.string().optional(),
|
|
95
|
+
background: z.string().optional()
|
|
96
|
+
});
|
|
97
|
+
/**
|
|
98
|
+
* Union type that accepts both formats
|
|
99
|
+
*/
|
|
100
|
+
const SubtitleShape = z.union([SubtitleWithCompactWordsShape, SubtitleWithLegacyWordsShape]);
|
|
101
|
+
// ============================================================================
|
|
102
|
+
// COLLECTION SCHEMAS
|
|
103
|
+
// ============================================================================
|
|
104
|
+
/**
|
|
105
|
+
* Subtitle collection (language mapping)
|
|
106
|
+
*/
|
|
107
|
+
const SubtitleCollectionShape = z.record(z.string(), z.array(SubtitleShape));
|
|
108
|
+
// ============================================================================
|
|
109
|
+
// SCHEMA EXPORTS
|
|
110
|
+
// ============================================================================
|
|
111
|
+
export { CompactWordMetadataShape, CompactWordTupleShape, SubtitleWordShape, SubtitleWithCompactWordsShape, SubtitleWithLegacyWordsShape, SubtitleShape, SubtitleCollectionShape };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isValidColor(color: string): boolean;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SeedFactory - A utility for deterministic seed-based value generation
|
|
3
|
+
*
|
|
4
|
+
* This class implements functionality for creating deterministic sequences
|
|
5
|
+
* from seed values, useful for consistent animations and randomization.
|
|
6
|
+
*/
|
|
7
|
+
export declare class SeedFactory {
|
|
8
|
+
/**
|
|
9
|
+
* Generates a hash value from a string
|
|
10
|
+
* Implementation of djb2 hash algorithm
|
|
11
|
+
*
|
|
12
|
+
* @param str The string to hash
|
|
13
|
+
* @returns A numeric hash value
|
|
14
|
+
*/
|
|
15
|
+
static hash(str: string): number;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a deterministic random number generator
|
|
18
|
+
*
|
|
19
|
+
* @param seed The seed value for random generation
|
|
20
|
+
* @returns A function that produces deterministic random numbers between 0 and 1
|
|
21
|
+
*/
|
|
22
|
+
static createRandomGenerator(seed?: number): () => number;
|
|
23
|
+
/**
|
|
24
|
+
* Generates a deterministic array of values selected from possible values
|
|
25
|
+
*
|
|
26
|
+
* @param seed The seed value for deterministic selection
|
|
27
|
+
* @param possibleValues Array of possible values to select from
|
|
28
|
+
* @param count Number of items to generate (default: 50)
|
|
29
|
+
* @returns Array of values in deterministic pseudo-random order
|
|
30
|
+
*/
|
|
31
|
+
static generateValues<T>(seed: number, possibleValues: T[], count?: number): T[];
|
|
32
|
+
/**
|
|
33
|
+
* Generates an array of possible values within a numeric range
|
|
34
|
+
*
|
|
35
|
+
* @param min Minimum value (inclusive)
|
|
36
|
+
* @param max Maximum value (inclusive)
|
|
37
|
+
* @param step Step size between values (default: 1)
|
|
38
|
+
* @returns Array of all possible values in the range
|
|
39
|
+
*/
|
|
40
|
+
static generatePossibleValues(min: number, max: number, step?: number): number[];
|
|
41
|
+
/**
|
|
42
|
+
* Generates deterministic numeric values within a range
|
|
43
|
+
*
|
|
44
|
+
* @param seed The seed value for deterministic generation
|
|
45
|
+
* @param min Minimum value (inclusive)
|
|
46
|
+
* @param max Maximum value (inclusive)
|
|
47
|
+
* @param step Step size between values (default: 1)
|
|
48
|
+
* @param count Number of items to generate (default: 50)
|
|
49
|
+
* @returns Array of deterministic numeric values
|
|
50
|
+
*/
|
|
51
|
+
static generateRangeValues(seed: number, min: number, max: number, step?: number, count?: number): number[];
|
|
52
|
+
/**
|
|
53
|
+
* Converts an array to a seed value
|
|
54
|
+
*
|
|
55
|
+
* @param array Array to convert to seed
|
|
56
|
+
* @returns Numeric seed value
|
|
57
|
+
*/
|
|
58
|
+
static arrayToSeed<T>(array: T[]): number;
|
|
59
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SeedFactory - A utility for deterministic seed-based value generation
|
|
3
|
+
*
|
|
4
|
+
* This class implements functionality for creating deterministic sequences
|
|
5
|
+
* from seed values, useful for consistent animations and randomization.
|
|
6
|
+
*/
|
|
7
|
+
export class SeedFactory {
|
|
8
|
+
/**
|
|
9
|
+
* Generates a hash value from a string
|
|
10
|
+
* Implementation of djb2 hash algorithm
|
|
11
|
+
*
|
|
12
|
+
* @param str The string to hash
|
|
13
|
+
* @returns A numeric hash value
|
|
14
|
+
*/
|
|
15
|
+
static hash(str) {
|
|
16
|
+
// Optional: Limit string length to prevent excessive computation
|
|
17
|
+
const limitedStr = str.length > 10000 ? str.substring(0, 10000) : str;
|
|
18
|
+
let hash = 5381;
|
|
19
|
+
for (let i = 0; i < limitedStr.length; i++) {
|
|
20
|
+
hash = (hash * 33) ^ limitedStr.charCodeAt(i);
|
|
21
|
+
}
|
|
22
|
+
return hash >>> 0;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates a deterministic random number generator
|
|
26
|
+
*
|
|
27
|
+
* @param seed The seed value for random generation
|
|
28
|
+
* @returns A function that produces deterministic random numbers between 0 and 1
|
|
29
|
+
*/
|
|
30
|
+
static createRandomGenerator(seed = 5381) {
|
|
31
|
+
let currentSeed = seed;
|
|
32
|
+
return function () {
|
|
33
|
+
// Simple LCG (Linear Congruential Generator)
|
|
34
|
+
currentSeed = (currentSeed * 9301 + 49297) % 233280;
|
|
35
|
+
return currentSeed / 233280;
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Generates a deterministic array of values selected from possible values
|
|
40
|
+
*
|
|
41
|
+
* @param seed The seed value for deterministic selection
|
|
42
|
+
* @param possibleValues Array of possible values to select from
|
|
43
|
+
* @param count Number of items to generate (default: 50)
|
|
44
|
+
* @returns Array of values in deterministic pseudo-random order
|
|
45
|
+
*/
|
|
46
|
+
static generateValues(seed, possibleValues, count = 50) {
|
|
47
|
+
if (!possibleValues.length)
|
|
48
|
+
return [];
|
|
49
|
+
// Create seeded random generator
|
|
50
|
+
const seededRandom = this.createRandomGenerator(seed);
|
|
51
|
+
const result = [];
|
|
52
|
+
// Fill array with deterministic selections
|
|
53
|
+
for (let i = 0; i < count; i++) {
|
|
54
|
+
const randomIndex = Math.floor(seededRandom() * possibleValues.length);
|
|
55
|
+
result.push(possibleValues[randomIndex]);
|
|
56
|
+
}
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Generates an array of possible values within a numeric range
|
|
61
|
+
*
|
|
62
|
+
* @param min Minimum value (inclusive)
|
|
63
|
+
* @param max Maximum value (inclusive)
|
|
64
|
+
* @param step Step size between values (default: 1)
|
|
65
|
+
* @returns Array of all possible values in the range
|
|
66
|
+
*/
|
|
67
|
+
static generatePossibleValues(min, max, step = 1) {
|
|
68
|
+
const values = [];
|
|
69
|
+
for (let i = min; i <= max; i += step) {
|
|
70
|
+
values.push(Number(i.toFixed(2))); // Fix precision
|
|
71
|
+
}
|
|
72
|
+
return values;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Generates deterministic numeric values within a range
|
|
76
|
+
*
|
|
77
|
+
* @param seed The seed value for deterministic generation
|
|
78
|
+
* @param min Minimum value (inclusive)
|
|
79
|
+
* @param max Maximum value (inclusive)
|
|
80
|
+
* @param step Step size between values (default: 1)
|
|
81
|
+
* @param count Number of items to generate (default: 50)
|
|
82
|
+
* @returns Array of deterministic numeric values
|
|
83
|
+
*/
|
|
84
|
+
static generateRangeValues(seed, min, max, step = 1, count = 50) {
|
|
85
|
+
// Generate all possible values in the range
|
|
86
|
+
const possibleValues = this.generatePossibleValues(min, max, step);
|
|
87
|
+
// Use the standard generateValues method with the possible values
|
|
88
|
+
return this.generateValues(seed, possibleValues, count);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Converts an array to a seed value
|
|
92
|
+
*
|
|
93
|
+
* @param array Array to convert to seed
|
|
94
|
+
* @returns Numeric seed value
|
|
95
|
+
*/
|
|
96
|
+
static arrayToSeed(array) {
|
|
97
|
+
return this.hash(JSON.stringify(array));
|
|
98
|
+
}
|
|
99
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ColorTypeShape, GradientDefinitionShape } from '..';
|
|
2
|
+
import tinycolor from 'tinycolor2';
|
|
3
|
+
function buildGradientCss(gradient) {
|
|
4
|
+
const colorsWithStops = gradient.colors
|
|
5
|
+
.map((col, index) => {
|
|
6
|
+
if (gradient.stops?.[index] !== undefined) {
|
|
7
|
+
return `${col} ${gradient.stops[index]}%`;
|
|
8
|
+
}
|
|
9
|
+
return col;
|
|
10
|
+
})
|
|
11
|
+
.join(', ');
|
|
12
|
+
if (gradient.type === 'linear') {
|
|
13
|
+
const angle = gradient.angle !== undefined ? `${gradient.angle}deg` : 'to bottom';
|
|
14
|
+
return `linear-gradient(${angle}, ${colorsWithStops})`;
|
|
15
|
+
}
|
|
16
|
+
else if (gradient.type === 'radial') {
|
|
17
|
+
let definition = '';
|
|
18
|
+
if (gradient.shape)
|
|
19
|
+
definition += gradient.shape;
|
|
20
|
+
if (gradient.position) {
|
|
21
|
+
definition += definition ? ` at ${gradient.position}` : `at ${gradient.position}`;
|
|
22
|
+
}
|
|
23
|
+
return `radial-gradient(${definition ? definition + ', ' : ''}${colorsWithStops})`;
|
|
24
|
+
}
|
|
25
|
+
return '';
|
|
26
|
+
}
|
|
27
|
+
export class ColorTransformer {
|
|
28
|
+
static transform(color, type) {
|
|
29
|
+
const styles = {};
|
|
30
|
+
const validTypes = ['text', 'background'];
|
|
31
|
+
if (!validTypes.includes(type)) {
|
|
32
|
+
return styles;
|
|
33
|
+
}
|
|
34
|
+
const resp = ColorTypeShape.safeParse(color);
|
|
35
|
+
if (!resp.success) {
|
|
36
|
+
return styles;
|
|
37
|
+
}
|
|
38
|
+
if (typeof resp.data === 'string') {
|
|
39
|
+
const output = tinycolor(resp.data);
|
|
40
|
+
if (output.isValid()) {
|
|
41
|
+
const prop = type === 'text' ? 'color' : 'backgroundColor';
|
|
42
|
+
if (output.getAlpha() === 0) {
|
|
43
|
+
styles[prop] = 'transparent';
|
|
44
|
+
return styles;
|
|
45
|
+
}
|
|
46
|
+
styles[prop] = output.toRgbString();
|
|
47
|
+
return styles;
|
|
48
|
+
}
|
|
49
|
+
return styles;
|
|
50
|
+
}
|
|
51
|
+
if (resp.data.type === 'linear' || resp.data.type === 'radial') {
|
|
52
|
+
const gradient = GradientDefinitionShape.safeParse(resp.data);
|
|
53
|
+
if (!gradient.success) {
|
|
54
|
+
return styles;
|
|
55
|
+
}
|
|
56
|
+
const prop = type === 'text' ? 'backgroundImage' : 'background';
|
|
57
|
+
styles[prop] = buildGradientCss(gradient.data);
|
|
58
|
+
if (type === 'text') {
|
|
59
|
+
styles.webkitBackgroundClip = 'text';
|
|
60
|
+
styles.backgroundClip = 'text';
|
|
61
|
+
styles.color = 'transparent';
|
|
62
|
+
}
|
|
63
|
+
return styles;
|
|
64
|
+
}
|
|
65
|
+
return styles;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import * as PIXI from 'pixi.js-legacy';
|
|
2
|
+
import type { ColorType } from '..';
|
|
3
|
+
interface PixiColorResult {
|
|
4
|
+
type: 'solid' | 'gradient';
|
|
5
|
+
color?: number;
|
|
6
|
+
texture?: PIXI.Texture;
|
|
7
|
+
width?: number;
|
|
8
|
+
height?: number;
|
|
9
|
+
}
|
|
10
|
+
interface BgShape {
|
|
11
|
+
enabled: boolean;
|
|
12
|
+
color: ColorType;
|
|
13
|
+
target?: string;
|
|
14
|
+
radius?: number;
|
|
15
|
+
}
|
|
16
|
+
type BackgroundShape = BgShape | ColorType | null | undefined;
|
|
17
|
+
export declare class PixiColorTransformer {
|
|
18
|
+
#private;
|
|
19
|
+
static transform(background: BackgroundShape, width: number, height: number): PixiColorResult;
|
|
20
|
+
static isGradient(background: BackgroundShape): boolean;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as PIXI from 'pixi.js-legacy';
|
|
2
|
+
import { ColorTypeShape, GradientDefinitionShape } from '..';
|
|
3
|
+
import tinycolor from 'tinycolor2';
|
|
4
|
+
export class PixiColorTransformer {
|
|
5
|
+
static transform(background, width, height) {
|
|
6
|
+
if (!background) {
|
|
7
|
+
return { type: 'solid', color: 0x000000 };
|
|
8
|
+
}
|
|
9
|
+
// Extract the actual color from the background
|
|
10
|
+
const color = this.#extractColor(background);
|
|
11
|
+
if (!color) {
|
|
12
|
+
return { type: 'solid', color: 0x000000 };
|
|
13
|
+
}
|
|
14
|
+
const resp = ColorTypeShape.safeParse(color);
|
|
15
|
+
if (!resp.success) {
|
|
16
|
+
return { type: 'solid', color: 0x000000 };
|
|
17
|
+
}
|
|
18
|
+
// Handle solid color
|
|
19
|
+
if (typeof resp.data === 'string') {
|
|
20
|
+
const output = tinycolor(resp.data);
|
|
21
|
+
if (output.isValid()) {
|
|
22
|
+
if (output.getAlpha() === 0) {
|
|
23
|
+
return { type: 'solid', color: 0x000000 };
|
|
24
|
+
}
|
|
25
|
+
return { type: 'solid', color: parseInt(output.toHex(), 16) };
|
|
26
|
+
}
|
|
27
|
+
return { type: 'solid', color: 0x000000 };
|
|
28
|
+
}
|
|
29
|
+
// Handle gradient
|
|
30
|
+
if (resp.data.type === 'linear' || resp.data.type === 'radial') {
|
|
31
|
+
const gradient = GradientDefinitionShape.safeParse(resp.data);
|
|
32
|
+
if (!gradient.success) {
|
|
33
|
+
return { type: 'solid', color: 0x000000 };
|
|
34
|
+
}
|
|
35
|
+
const canvas = this.#createGradientCanvas(gradient.data, width, height);
|
|
36
|
+
const texture = PIXI.Texture.from(canvas);
|
|
37
|
+
return { type: 'gradient', texture, width, height };
|
|
38
|
+
}
|
|
39
|
+
return { type: 'solid', color: 0x000000 };
|
|
40
|
+
}
|
|
41
|
+
static #extractColor(background) {
|
|
42
|
+
if (!background)
|
|
43
|
+
return null;
|
|
44
|
+
// If it's a direct ColorType (string or gradient object)
|
|
45
|
+
if (typeof background === 'string' ||
|
|
46
|
+
(typeof background === 'object' && 'type' in background)) {
|
|
47
|
+
return background;
|
|
48
|
+
}
|
|
49
|
+
// If it's a BgShape object
|
|
50
|
+
if (typeof background === 'object' && 'enabled' in background) {
|
|
51
|
+
const bgShape = background;
|
|
52
|
+
if (!bgShape.enabled)
|
|
53
|
+
return null;
|
|
54
|
+
return bgShape.color;
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
static #createGradientCanvas(gradient, width, height) {
|
|
59
|
+
const canvas = document.createElement('canvas');
|
|
60
|
+
canvas.width = width;
|
|
61
|
+
canvas.height = height;
|
|
62
|
+
const ctx = canvas.getContext('2d');
|
|
63
|
+
const colorsWithStops = gradient.colors.map((col, index) => {
|
|
64
|
+
if (gradient.stops?.[index] !== undefined) {
|
|
65
|
+
return { color: col, stop: gradient.stops[index] / 100 };
|
|
66
|
+
}
|
|
67
|
+
return { color: col, stop: index / (gradient.colors.length - 1) };
|
|
68
|
+
});
|
|
69
|
+
if (gradient.type === 'linear') {
|
|
70
|
+
const angle = gradient.angle !== undefined ? gradient.angle : 0;
|
|
71
|
+
const rad = (angle * Math.PI) / 180;
|
|
72
|
+
const x1 = (Math.cos(rad) * width) / 2 + width / 2;
|
|
73
|
+
const y1 = (Math.sin(rad) * height) / 2 + height / 2;
|
|
74
|
+
const gradientObj = ctx.createLinearGradient(width / 2, height / 2, x1, y1);
|
|
75
|
+
colorsWithStops.forEach(({ color, stop }) => {
|
|
76
|
+
gradientObj.addColorStop(stop, color);
|
|
77
|
+
});
|
|
78
|
+
ctx.fillStyle = gradientObj;
|
|
79
|
+
ctx.fillRect(0, 0, width, height);
|
|
80
|
+
}
|
|
81
|
+
else if (gradient.type === 'radial') {
|
|
82
|
+
// For radial gradients, we'll use a simplified approach
|
|
83
|
+
// PIXI doesn't have native radial gradient support, so we create a linear approximation
|
|
84
|
+
const gradientObj = ctx.createRadialGradient(width / 2, height / 2, 0, width / 2, height / 2, Math.max(width, height) / 2);
|
|
85
|
+
colorsWithStops.forEach(({ color, stop }) => {
|
|
86
|
+
gradientObj.addColorStop(stop, color);
|
|
87
|
+
});
|
|
88
|
+
ctx.fillStyle = gradientObj;
|
|
89
|
+
ctx.fillRect(0, 0, width, height);
|
|
90
|
+
}
|
|
91
|
+
return canvas;
|
|
92
|
+
}
|
|
93
|
+
static isGradient(background) {
|
|
94
|
+
if (!background)
|
|
95
|
+
return false;
|
|
96
|
+
const color = this.#extractColor(background);
|
|
97
|
+
if (!color)
|
|
98
|
+
return false;
|
|
99
|
+
const resp = ColorTypeShape.safeParse(color);
|
|
100
|
+
if (!resp.success)
|
|
101
|
+
return false;
|
|
102
|
+
return (typeof resp.data === 'object' && (resp.data.type === 'linear' || resp.data.type === 'radial'));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const computeXYAngle = (angleInDeg, width, height) => {
|
|
2
|
+
// Compute angle in radians - CSS starts from 180 degrees and goes clockwise
|
|
3
|
+
// Math functions start from 0 and go anti-clockwise so we use 180 - angleInDeg to convert between the two
|
|
4
|
+
const angle = ((180 - angleInDeg) * Math.PI) / 180;
|
|
5
|
+
// const angle = ((180 - angleInDeg) / 180) * Math.PI;
|
|
6
|
+
// // This computes the length such that the start/stop points will be at the corners
|
|
7
|
+
const length = Math.abs(width * Math.sin(angle)) + Math.abs(height * Math.cos(angle));
|
|
8
|
+
// Compute the actual x,y points based on the angle, length of the gradient line and the center of the div
|
|
9
|
+
const halfx = (Math.sin(angle) * length) / 2.0;
|
|
10
|
+
const halfy = (Math.cos(angle) * length) / 2.0;
|
|
11
|
+
const cx = width / 2.0;
|
|
12
|
+
const cy = height / 2.0;
|
|
13
|
+
const x1 = Math.round(cx - halfx);
|
|
14
|
+
const y1 = Math.round(cy - halfy);
|
|
15
|
+
const x2 = Math.round(cx + halfx);
|
|
16
|
+
const y2 = Math.round(cy + halfy);
|
|
17
|
+
return { x1, x2, y1, y2 };
|
|
18
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
async function waitForAllFonts() {
|
|
2
|
+
// Guard clause for server-side rendering or non-browser environments
|
|
3
|
+
if (typeof document === 'undefined' || !document.fonts) {
|
|
4
|
+
return;
|
|
5
|
+
}
|
|
6
|
+
try {
|
|
7
|
+
await document.fonts.ready;
|
|
8
|
+
}
|
|
9
|
+
catch (error) {
|
|
10
|
+
console.warn('One or more fonts failed to load.', error);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export const loadFonts = async function (fonts) {
|
|
14
|
+
// const results = await PIXI.Assets.load(fonts);
|
|
15
|
+
const googleFonts = fonts.reduce((acc, font) => {
|
|
16
|
+
if (font.source == 'google' && font.data) {
|
|
17
|
+
acc.push(font.data.family);
|
|
18
|
+
}
|
|
19
|
+
return acc;
|
|
20
|
+
}, []);
|
|
21
|
+
if (document && googleFonts.length > 0 && typeof document !== 'undefined') {
|
|
22
|
+
const fontPromises = googleFonts.map((font) => new Promise((resolve) => {
|
|
23
|
+
const link = document.createElement('link');
|
|
24
|
+
link.href = `https://fonts.googleapis.com/css?family=${encodeURIComponent(font)}`;
|
|
25
|
+
link.rel = 'stylesheet';
|
|
26
|
+
link.onload = () => resolve(true);
|
|
27
|
+
link.onerror = () => {
|
|
28
|
+
console.warn(`Failed to load font: ${font}`);
|
|
29
|
+
resolve(false);
|
|
30
|
+
};
|
|
31
|
+
document.head.appendChild(link);
|
|
32
|
+
}));
|
|
33
|
+
await Promise.all(fontPromises);
|
|
34
|
+
}
|
|
35
|
+
await waitForAllFonts();
|
|
36
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare function getIconCode(char: string): string;
|
|
2
|
+
export declare const apis: {
|
|
3
|
+
twemoji: (code: string) => string;
|
|
4
|
+
openmoji: string;
|
|
5
|
+
blobmoji: string;
|
|
6
|
+
noto: string;
|
|
7
|
+
fluent: (code: string) => string;
|
|
8
|
+
fluentFlat: (code: string) => string;
|
|
9
|
+
};
|
|
10
|
+
export declare function loadEmoji(type: keyof typeof apis, code: string): Promise<any>;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
const U200D = String.fromCharCode(8205);
|
|
2
|
+
const UFE0Fg = /\uFE0F/g;
|
|
3
|
+
export function getIconCode(char) {
|
|
4
|
+
return toCodePoint(char.indexOf(U200D) < 0 ? char.replace(UFE0Fg, "") : char);
|
|
5
|
+
}
|
|
6
|
+
function toCodePoint(unicodeSurrogates) {
|
|
7
|
+
const r = [];
|
|
8
|
+
let c = 0, p = 0, i = 0;
|
|
9
|
+
while (i < unicodeSurrogates.length) {
|
|
10
|
+
c = unicodeSurrogates.charCodeAt(i++);
|
|
11
|
+
if (p) {
|
|
12
|
+
r.push((65536 + ((p - 55296) << 10) + (c - 56320)).toString(16));
|
|
13
|
+
p = 0;
|
|
14
|
+
}
|
|
15
|
+
else if (55296 <= c && c <= 56319) {
|
|
16
|
+
p = c;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
r.push(c.toString(16));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return r.join("-");
|
|
23
|
+
}
|
|
24
|
+
export const apis = {
|
|
25
|
+
twemoji: (code) => "https://cdnjs.cloudflare.com/ajax/libs/twemoji/14.0.2/svg/" +
|
|
26
|
+
code.toLowerCase() +
|
|
27
|
+
".svg",
|
|
28
|
+
openmoji: "https://cdn.jsdelivr.net/npm/@svgmoji/openmoji@2.0.0/svg/",
|
|
29
|
+
blobmoji: "https://cdn.jsdelivr.net/npm/@svgmoji/blob@2.0.0/svg/",
|
|
30
|
+
noto: "https://cdn.jsdelivr.net/gh/svgmoji/svgmoji/packages/svgmoji__noto/svg/",
|
|
31
|
+
fluent: (code) => "https://cdn.jsdelivr.net/gh/shuding/fluentui-emoji-unicode/assets/" +
|
|
32
|
+
code.toLowerCase() +
|
|
33
|
+
"_color.svg",
|
|
34
|
+
fluentFlat: (code) => "https://cdn.jsdelivr.net/gh/shuding/fluentui-emoji-unicode/assets/" +
|
|
35
|
+
code.toLowerCase() +
|
|
36
|
+
"_flat.svg",
|
|
37
|
+
};
|
|
38
|
+
const emojiCache = {};
|
|
39
|
+
export function loadEmoji(type, code) {
|
|
40
|
+
const key = type + ":" + code;
|
|
41
|
+
if (key in emojiCache)
|
|
42
|
+
return emojiCache[key];
|
|
43
|
+
if (!type || !apis[type]) {
|
|
44
|
+
type = "twemoji";
|
|
45
|
+
}
|
|
46
|
+
const api = apis[type];
|
|
47
|
+
if (typeof api === "function") {
|
|
48
|
+
return (emojiCache[key] = fetch(api(code)).then((r) => r.text()));
|
|
49
|
+
}
|
|
50
|
+
return (emojiCache[key] = fetch(`${api}${code.toUpperCase()}.svg`).then((r) => r.text()));
|
|
51
|
+
}
|