@x4r1s3/baileys 0.0.0-stage → 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 +1262 -2
- package/SECURITY.md +47 -0
- package/WAProto/V +1 -0
- package/WAProto/WAProto.proto +8892 -0
- package/WAProto/index.d.ts +104128 -0
- package/WAProto/index.js +334920 -0
- package/assets/rolling-circle.svg +133 -0
- package/assets/x4r1s3-banner.svg +32 -0
- package/engine-requirements.js +27 -0
- package/lib/Builders/A2UI.js +245 -0
- package/lib/Builders/AIRich.js +179 -0
- package/lib/Builders/Button.js +108 -0
- package/lib/Builders/CFC.js +284 -0
- package/lib/Builders/Carousel.js +81 -0
- package/lib/Call/THIRD_PARTY_LICENSE.txt +21 -0
- package/lib/Call/audio-feeder.mjs +179 -0
- package/lib/Call/audio-recorder.mjs +250 -0
- package/lib/Call/fetch-wasm-resources.mjs +104 -0
- package/lib/Call/index.mjs +680 -0
- package/lib/Call/relay-transport.mjs +563 -0
- package/lib/Call/signaling.mjs +641 -0
- package/lib/Call/types.mjs +17 -0
- package/lib/Call/video-feeder.mjs +94 -0
- package/lib/Call/wasm-engine.mjs +1372 -0
- package/lib/Call/worker-bootstrap.mjs +1042 -0
- package/lib/Defaults/ban-checker.js +56 -0
- package/lib/Defaults/index.js +170 -0
- package/lib/Signal/Group/ciphertext-message.js +23 -0
- package/lib/Signal/Group/group-session-builder.js +41 -0
- package/lib/Signal/Group/group_cipher.js +93 -0
- package/lib/Signal/Group/index.js +23 -0
- package/lib/Signal/Group/keyhelper.js +29 -0
- package/lib/Signal/Group/sender-chain-key.js +37 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +74 -0
- package/lib/Signal/Group/sender-key-message.js +77 -0
- package/lib/Signal/Group/sender-key-name.js +59 -0
- package/lib/Signal/Group/sender-key-record.js +52 -0
- package/lib/Signal/Group/sender-key-state.js +95 -0
- package/lib/Signal/Group/sender-message-key.js +37 -0
- package/lib/Signal/libsignal.js +440 -0
- package/lib/Signal/lid-mapping.js +292 -0
- package/lib/Socket/Client/index.js +14 -0
- package/lib/Socket/Client/types.js +22 -0
- package/lib/Socket/Client/websocket.js +65 -0
- package/lib/Socket/aigroups.js +327 -0
- package/lib/Socket/ban-checker.js +165 -0
- package/lib/Socket/business.js +419 -0
- package/lib/Socket/chats.js +1921 -0
- package/lib/Socket/communities.js +443 -0
- package/lib/Socket/graphql.js +911 -0
- package/lib/Socket/groups.js +561 -0
- package/lib/Socket/index.js +49 -0
- package/lib/Socket/interactive-handler.js +612 -0
- package/lib/Socket/interop.js +575 -0
- package/lib/Socket/managed-account.js +220 -0
- package/lib/Socket/messages-recv.js +2191 -0
- package/lib/Socket/messages-send.js +4104 -0
- package/lib/Socket/mex.js +53 -0
- package/lib/Socket/newsletter.js +291 -0
- package/lib/Socket/privacy.js +458 -0
- package/lib/Socket/registration.js +440 -0
- package/lib/Socket/socket.js +1029 -0
- package/lib/Socket/status-actions.js +287 -0
- package/lib/Socket/username.js +241 -0
- package/lib/Store/index.js +16 -0
- package/lib/Store/make-cache-manager-store.js +101 -0
- package/lib/Store/make-in-memory-store.js +432 -0
- package/lib/Store/make-ordered-dictionary.js +90 -0
- package/lib/Store/object-repository.js +35 -0
- package/lib/Types/Auth.js +13 -0
- package/lib/Types/Bussines.js +13 -0
- package/lib/Types/Call.js +13 -0
- package/lib/Types/Chat.js +19 -0
- package/lib/Types/Contact.js +13 -0
- package/lib/Types/Events.js +13 -0
- package/lib/Types/GroupMetadata.js +13 -0
- package/lib/Types/Label.js +36 -0
- package/lib/Types/LabelAssociation.js +18 -0
- package/lib/Types/Message.js +30 -0
- package/lib/Types/Mex.js +53 -0
- package/lib/Types/Product.js +13 -0
- package/lib/Types/RichType.js +34 -0
- package/lib/Types/Signal.js +13 -0
- package/lib/Types/Socket.js +14 -0
- package/lib/Types/State.js +60 -0
- package/lib/Types/USync.js +13 -0
- package/lib/Types/index.js +37 -0
- package/lib/Utils/auth-utils.js +313 -0
- package/lib/Utils/ban-checker.js +48 -0
- package/lib/Utils/bot-capabilities.js +96 -0
- package/lib/Utils/bot-planning-replay.js +177 -0
- package/lib/Utils/browser-utils.js +40 -0
- package/lib/Utils/business.js +242 -0
- package/lib/Utils/c2582.js +147 -0
- package/lib/Utils/chat-utils.js +905 -0
- package/lib/Utils/companion-reg-client-utils.js +44 -0
- package/lib/Utils/consumer-application.js +114 -0
- package/lib/Utils/crypto.js +129 -0
- package/lib/Utils/decode-wa-message.js +496 -0
- package/lib/Utils/direct-chat-theme.js +164 -0
- package/lib/Utils/event-buffer.js +601 -0
- package/lib/Utils/experimental-proto.js +206 -0
- package/lib/Utils/games/miniapp.js +17 -0
- package/lib/Utils/games/slot-machine.js +270 -0
- package/lib/Utils/games/website-preview.js +306 -0
- package/lib/Utils/generics.js +402 -0
- package/lib/Utils/group-history.js +68 -0
- package/lib/Utils/group-wallpaper.js +168 -0
- package/lib/Utils/history.js +162 -0
- package/lib/Utils/identity-change-handler.js +60 -0
- package/lib/Utils/index.js +61 -0
- package/lib/Utils/jid-display-normalization.js +221 -0
- package/lib/Utils/link-preview.js +96 -0
- package/lib/Utils/logger.js +14 -0
- package/lib/Utils/lt-hash.js +19 -0
- package/lib/Utils/make-mutex.js +44 -0
- package/lib/Utils/message-composer.js +709 -0
- package/lib/Utils/message-inspect.js +79 -0
- package/lib/Utils/message-retry-manager.js +253 -0
- package/lib/Utils/message-security.js +167 -0
- package/lib/Utils/messages-media.js +1027 -0
- package/lib/Utils/messages.js +2467 -0
- package/lib/Utils/meta-ai-msmsg.js +215 -0
- package/lib/Utils/meta-compositing.js +239 -0
- package/lib/Utils/native-flow.js +158 -0
- package/lib/Utils/newsletter-live-update-utils.js +74 -0
- package/lib/Utils/newsletter-status-utils.js +152 -0
- package/lib/Utils/noise-handler.js +212 -0
- package/lib/Utils/offline-node-processor.js +51 -0
- package/lib/Utils/poll-manager.js +206 -0
- package/lib/Utils/portable-compat.js +12 -0
- package/lib/Utils/pre-key-manager.js +117 -0
- package/lib/Utils/process-message.js +610 -0
- package/lib/Utils/reporting-utils.js +269 -0
- package/lib/Utils/rich-message-utils.js +2841 -0
- package/lib/Utils/scheduled-message.js +107 -0
- package/lib/Utils/signal.js +212 -0
- package/lib/Utils/source-grep.js +57 -0
- package/lib/Utils/stanza-ack.js +49 -0
- package/lib/Utils/sticker-annotation.js +87 -0
- package/lib/Utils/sync-action-utils.js +59 -0
- package/lib/Utils/tc-token-utils.js +174 -0
- package/lib/Utils/use-multi-file-auth-state.js +132 -0
- package/lib/Utils/use-single-file-auth-state.js +108 -0
- package/lib/Utils/use-sqlite-auth-state.js +120 -0
- package/lib/Utils/validate-connection.js +220 -0
- package/lib/Utils/view-once-utils.js +218 -0
- package/lib/Utils/voip-rekey.js +32 -0
- package/lib/Utils/website-preview.js +27 -0
- package/lib/Utils/welcome-flow.js +228 -0
- package/lib/Utils/x4r1s3.js +144 -0
- package/lib/WABinary/constants.js +1475 -0
- package/lib/WABinary/decode.js +273 -0
- package/lib/WABinary/encode.js +231 -0
- package/lib/WABinary/generic-utils.js +242 -0
- package/lib/WABinary/index.js +17 -0
- package/lib/WABinary/jid-utils.js +107 -0
- package/lib/WABinary/types.js +13 -0
- package/lib/WAM/BinaryInfo.js +21 -0
- package/lib/WAM/constants.js +22864 -0
- package/lib/WAM/encode.js +161 -0
- package/lib/WAM/index.js +15 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +108 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +68 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +65 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +82 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +40 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +46 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +36 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +62 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +40 -0
- package/lib/WAUSync/Protocols/index.js +24 -0
- package/lib/WAUSync/USyncQuery.js +213 -0
- package/lib/WAUSync/USyncUser.js +66 -0
- package/lib/WAUSync/index.js +15 -0
- package/lib/antiban.cjs +4726 -0
- package/lib/index.d.ts +1285 -0
- package/lib/index.js +30 -0
- package/package.json +125 -4
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { proto } from '../../WAProto/index.js';
|
|
3
|
+
|
|
4
|
+
const assertNonEmptyString = (value, field) => {
|
|
5
|
+
if (typeof value !== 'string' || value.trim().length === 0) {
|
|
6
|
+
throw new Boom(`${field} must be a non-empty string`, { statusCode: 400 });
|
|
7
|
+
}
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const assertUint32 = (value, field) => {
|
|
11
|
+
if (!Number.isInteger(value) || value < 0 || value > 0xFFFFFFFF) {
|
|
12
|
+
throw new Boom(`${field} must be an integer uint32`, { statusCode: 400 });
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const assertInt64 = (value, field) => {
|
|
17
|
+
if (!(Number.isSafeInteger(value) || typeof value === 'bigint' || typeof value === 'string') || Number(value) < 0) {
|
|
18
|
+
throw new Boom(`${field} must be a non-negative int64-compatible value`, { statusCode: 400 });
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const assertBuffer = (value, field) => {
|
|
23
|
+
if (!Buffer.isBuffer(value) && !(value instanceof Uint8Array)) {
|
|
24
|
+
throw new Boom(`${field} must be a Buffer or Uint8Array`, { statusCode: 400 });
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/** Build a conversation draft value for local/app-state serialization. */
|
|
29
|
+
export const buildConversationDraft = ({ content, editTimestampMs, editorDeviceId } = {}) => {
|
|
30
|
+
if (!content || typeof content !== 'object' || Array.isArray(content)) {
|
|
31
|
+
throw new Boom('content must be a Message object', { statusCode: 400 });
|
|
32
|
+
}
|
|
33
|
+
const verificationError = proto.Message.verify(content);
|
|
34
|
+
if (verificationError) throw new Boom(`content is not a valid Message: ${verificationError}`, { statusCode: 400 });
|
|
35
|
+
assertInt64(editTimestampMs, 'editTimestampMs');
|
|
36
|
+
if (editorDeviceId !== undefined) assertUint32(editorDeviceId, 'editorDeviceId');
|
|
37
|
+
return proto.ConversationDraft.fromObject({ content, editTimestampMs, editorDeviceId });
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Build a protocol-wrapped draft-sync message. This prepares a protobuf only;
|
|
42
|
+
* the correct peer/device routing for draft sync is not verified here.
|
|
43
|
+
*/
|
|
44
|
+
export const buildDraftMessageSync = ({ chatJid, altChatJid, action, editTimestampMs, draft, clearReason } = {}) => {
|
|
45
|
+
assertNonEmptyString(chatJid, 'chatJid');
|
|
46
|
+
if (altChatJid !== undefined) assertNonEmptyString(altChatJid, 'altChatJid');
|
|
47
|
+
if (![proto.DraftMessageSync.Action.SET, proto.DraftMessageSync.Action.CLEAR].includes(action)) {
|
|
48
|
+
throw new Boom('action must be DraftMessageSync.Action.SET or CLEAR', { statusCode: 400 });
|
|
49
|
+
}
|
|
50
|
+
if (!Number.isSafeInteger(editTimestampMs) || editTimestampMs < 0) {
|
|
51
|
+
throw new Boom('editTimestampMs must be a non-negative safe integer', { statusCode: 400 });
|
|
52
|
+
}
|
|
53
|
+
if (action === proto.DraftMessageSync.Action.SET) {
|
|
54
|
+
if (!draft || typeof draft !== 'object' || Array.isArray(draft)) {
|
|
55
|
+
throw new Boom('draft is required when action is SET', { statusCode: 400 });
|
|
56
|
+
}
|
|
57
|
+
const verificationError = proto.Message.verify(draft);
|
|
58
|
+
if (verificationError) {
|
|
59
|
+
throw new Boom(`draft is not a valid Message: ${verificationError}`, { statusCode: 400 });
|
|
60
|
+
}
|
|
61
|
+
if (clearReason !== undefined) {
|
|
62
|
+
throw new Boom('clearReason is only valid when action is CLEAR', { statusCode: 400 });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
if (draft !== undefined) {
|
|
67
|
+
throw new Boom('draft is not valid when action is CLEAR', { statusCode: 400 });
|
|
68
|
+
}
|
|
69
|
+
if (![proto.DraftMessageSync.ClearReason.USER_CLEARED,
|
|
70
|
+
proto.DraftMessageSync.ClearReason.SENT,
|
|
71
|
+
proto.DraftMessageSync.ClearReason.CHAT_LOCKED,
|
|
72
|
+
proto.DraftMessageSync.ClearReason.REPLACED_BY_NON_TEXT].includes(clearReason)) {
|
|
73
|
+
throw new Boom('clearReason must be a non-zero DraftMessageSync.ClearReason when action is CLEAR', { statusCode: 400 });
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return proto.Message.fromObject({
|
|
77
|
+
protocolMessage: {
|
|
78
|
+
type: proto.Message.ProtocolMessage.Type.DRAFT_MESSAGE_SYNC,
|
|
79
|
+
draftMessageSync: {
|
|
80
|
+
chatJid,
|
|
81
|
+
...(altChatJid !== undefined ? { altChatJid } : {}),
|
|
82
|
+
action,
|
|
83
|
+
editTimestampMs,
|
|
84
|
+
...(draft !== undefined ? { draft } : {}),
|
|
85
|
+
...(clearReason !== undefined ? { clearReason } : {})
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
/** Build a membership form protobuf; no verified stanza or publish transport is implied. */
|
|
92
|
+
export const buildGroupMembershipForm = ({ questions, memberTagPrompt, schemaVersion } = {}) => {
|
|
93
|
+
if (!Array.isArray(questions) || questions.length === 0) {
|
|
94
|
+
throw new Boom('questions must contain at least one question', { statusCode: 400 });
|
|
95
|
+
}
|
|
96
|
+
for (const [index, question] of questions.entries()) {
|
|
97
|
+
assertNonEmptyString(question?.text, `questions[${index}].text`);
|
|
98
|
+
}
|
|
99
|
+
if (memberTagPrompt !== undefined) assertNonEmptyString(memberTagPrompt, 'memberTagPrompt');
|
|
100
|
+
if (schemaVersion !== undefined) assertUint32(schemaVersion, 'schemaVersion');
|
|
101
|
+
return proto.GroupMembershipForm.fromObject({ questions, memberTagPrompt, schemaVersion });
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/** Build a membership-form submission protobuf; no verified group submission transport is implied. */
|
|
105
|
+
export const buildGroupMembershipFormSubmission = ({ questionAnswers = [], memberTagAnswer, schemaVersion } = {}) => {
|
|
106
|
+
if (!Array.isArray(questionAnswers)) {
|
|
107
|
+
throw new Boom('questionAnswers must be an array', { statusCode: 400 });
|
|
108
|
+
}
|
|
109
|
+
if (questionAnswers.length === 0 && memberTagAnswer === undefined) {
|
|
110
|
+
throw new Boom('at least one question answer or memberTagAnswer is required', { statusCode: 400 });
|
|
111
|
+
}
|
|
112
|
+
for (const [index, answer] of questionAnswers.entries()) {
|
|
113
|
+
assertNonEmptyString(answer?.question?.text, `questionAnswers[${index}].question.text`);
|
|
114
|
+
if (typeof answer?.answer !== 'string') {
|
|
115
|
+
throw new Boom(`questionAnswers[${index}].answer must be a string`, { statusCode: 400 });
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
if (memberTagAnswer !== undefined) {
|
|
119
|
+
assertNonEmptyString(memberTagAnswer?.prompt, 'memberTagAnswer.prompt');
|
|
120
|
+
assertNonEmptyString(memberTagAnswer?.memberTag, 'memberTagAnswer.memberTag');
|
|
121
|
+
}
|
|
122
|
+
if (schemaVersion !== undefined) assertUint32(schemaVersion, 'schemaVersion');
|
|
123
|
+
return proto.GroupMembershipFormSubmission.fromObject({ questionAnswers, memberTagAnswer, schemaVersion });
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
/** Build the public-key container; this does not perform key generation or encryption. */
|
|
127
|
+
export const buildMembershipFormPublicKeys = ({ mlKemPublicKey, x25519PublicKey } = {}) => {
|
|
128
|
+
assertBuffer(mlKemPublicKey, 'mlKemPublicKey');
|
|
129
|
+
assertBuffer(x25519PublicKey, 'x25519PublicKey');
|
|
130
|
+
return proto.MembershipFormPublicKeys.fromObject({ mlKemPublicKey, x25519PublicKey });
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
/** Build an already-encrypted join-request payload without exposing crypto primitives. */
|
|
134
|
+
export const buildEncryptedJoinRequestPayload = ({ encryptedAnswers, encIv, signalIdentityPublicKey, kemCiphertext } = {}) => {
|
|
135
|
+
assertBuffer(encryptedAnswers, 'encryptedAnswers');
|
|
136
|
+
assertBuffer(encIv, 'encIv');
|
|
137
|
+
assertBuffer(signalIdentityPublicKey, 'signalIdentityPublicKey');
|
|
138
|
+
assertBuffer(kemCiphertext, 'kemCiphertext');
|
|
139
|
+
return proto.EncryptedJoinRequestPayload.fromObject({ encryptedAnswers, encIv, signalIdentityPublicKey, kemCiphertext });
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
/** Build validated experimental MusicMessage lyrics metadata. Rendering is not guaranteed. */
|
|
143
|
+
export const buildMusicLyrics = ({ lines } = {}) => {
|
|
144
|
+
if (!Array.isArray(lines) || lines.length === 0) throw new Boom('lines must contain at least one lyric line', { statusCode: 400 });
|
|
145
|
+
for (const [lineIndex, line] of lines.entries()) {
|
|
146
|
+
assertNonEmptyString(line?.text, `lines[${lineIndex}].text`);
|
|
147
|
+
if (line.startTimeInMs !== undefined) assertInt64(line.startTimeInMs, `lines[${lineIndex}].startTimeInMs`);
|
|
148
|
+
if (line.endTimeInMs !== undefined) assertInt64(line.endTimeInMs, `lines[${lineIndex}].endTimeInMs`);
|
|
149
|
+
if (line.wordOffsets !== undefined) {
|
|
150
|
+
if (!Array.isArray(line.wordOffsets)) throw new Boom(`lines[${lineIndex}].wordOffsets must be an array`, { statusCode: 400 });
|
|
151
|
+
for (const [offsetIndex, offset] of line.wordOffsets.entries()) {
|
|
152
|
+
for (const field of ['startIndex', 'endIndex']) {
|
|
153
|
+
if (offset[field] !== undefined) assertUint32(offset[field], `lines[${lineIndex}].wordOffsets[${offsetIndex}].${field}`);
|
|
154
|
+
}
|
|
155
|
+
for (const field of ['startOffsetMs', 'endOffsetMs']) {
|
|
156
|
+
if (offset[field] !== undefined) assertInt64(offset[field], `lines[${lineIndex}].wordOffsets[${offsetIndex}].${field}`);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return proto.Message.MusicMessage.Lyrics.fromObject({ lines });
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
/** Build a MusicMessage with validated experimental lyrics/style metadata. */
|
|
165
|
+
export const buildMusicMessage = ({ embeddedMusic, songUri, artworkUri, style, contextInfo, lyrics } = {}) => {
|
|
166
|
+
if (songUri !== undefined) assertNonEmptyString(songUri, 'songUri');
|
|
167
|
+
if (artworkUri !== undefined) assertNonEmptyString(artworkUri, 'artworkUri');
|
|
168
|
+
if (style !== undefined && !Object.values(proto.Message.MusicMessage.MusicMessageStyle).includes(style)) {
|
|
169
|
+
throw new Boom('style must be a valid MusicMessageStyle value', { statusCode: 400 });
|
|
170
|
+
}
|
|
171
|
+
if (lyrics !== undefined && !(lyrics instanceof proto.Message.MusicMessage.Lyrics)) lyrics = buildMusicLyrics(lyrics);
|
|
172
|
+
return proto.Message.MusicMessage.fromObject({ embeddedMusic, songUri, artworkUri, style, contextInfo, lyrics });
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/** Build the status-template attribution metadata used by the status send helper. */
|
|
176
|
+
export const buildStatusTemplateAttribution = ({ templateId, templateName, thumbnailUrl } = {}) => {
|
|
177
|
+
assertNonEmptyString(templateId, 'templateId');
|
|
178
|
+
if (templateName !== undefined) assertNonEmptyString(templateName, 'templateName');
|
|
179
|
+
if (thumbnailUrl !== undefined) assertNonEmptyString(thumbnailUrl, 'thumbnailUrl');
|
|
180
|
+
return proto.StatusAttribution.fromObject({
|
|
181
|
+
type: proto.StatusAttribution.Type.STATUS_TEMPLATES,
|
|
182
|
+
statusTemplate: { templateId, templateName, thumbnailUrl }
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
/** Add experimental template attribution without changing other status context metadata. */
|
|
187
|
+
export const withStatusTemplateAttribution = (content, template) => {
|
|
188
|
+
if (!content || typeof content !== 'object' || Array.isArray(content)) {
|
|
189
|
+
throw new Boom('status content must be an object', { statusCode: 400 });
|
|
190
|
+
}
|
|
191
|
+
const contextInfo = content.contextInfo;
|
|
192
|
+
if (contextInfo !== undefined && (!contextInfo || typeof contextInfo !== 'object' || Array.isArray(contextInfo))) {
|
|
193
|
+
throw new Boom('content.contextInfo must be an object when provided', { statusCode: 400 });
|
|
194
|
+
}
|
|
195
|
+
const statusAttributions = contextInfo?.statusAttributions ?? [];
|
|
196
|
+
if (!Array.isArray(statusAttributions)) {
|
|
197
|
+
throw new Boom('content.contextInfo.statusAttributions must be an array', { statusCode: 400 });
|
|
198
|
+
}
|
|
199
|
+
return {
|
|
200
|
+
...content,
|
|
201
|
+
contextInfo: {
|
|
202
|
+
...contextInfo,
|
|
203
|
+
statusAttributions: [...statusAttributions, buildStatusTemplateAttribution(template)]
|
|
204
|
+
}
|
|
205
|
+
};
|
|
206
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @X4R1S3
|
|
3
|
+
*
|
|
4
|
+
* File: lib/Utils/games/miniapp.js
|
|
5
|
+
* About: Miniapp module for the X4R1S3 WhatsApp protocol client.
|
|
6
|
+
* Important exports: generateMiniAppHtml
|
|
7
|
+
* Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
|
|
8
|
+
*
|
|
9
|
+
* Copyright and attribution notice.
|
|
10
|
+
* Do not copy, reproduce, redistribute, modify, or create derivative works
|
|
11
|
+
* from this source without explicit written permission.
|
|
12
|
+
*/
|
|
13
|
+
/** Generate the attached interactive mini-app HTML game. */
|
|
14
|
+
export const generateMiniAppHtml = (options = {}) => {
|
|
15
|
+
const html = "<style>*{-webkit-tap-highlight-color:transparent;-webkit-user-select:none;user-select:none;-webkit-touch-callout:none}</style>\n<body style=\"margin:0;background:transparent;font-family:Arial,sans-serif;color:#eee;touch-action:manipulation;cursor:pointer\">\n<div style=\"width:100%;max-width:620px;margin:auto;padding:16px;box-sizing:border-box\">\n<div style=\"background:rgba(255,255,255,.06);backdrop-filter:blur(14px);-webkit-backdrop-filter:blur(14px);border:1px solid rgba(255,255,255,.15);border-radius:16px;overflow:hidden;box-shadow:0 8px 32px rgba(0,0,0,.35)\">\n<div style=\"padding:18px 20px;border-bottom:1px solid rgba(255,255,255,.12);display:flex;justify-content:space-between;align-items:center\">\n<div><div style=\"font-size:11px;letter-spacing:1.5px;color:rgba(255,255,255,.45)\">𝑶𝒓𝒊𝒈𝒊𝒏✦</div><div style=\"font-size:21px;font-weight:bold;color:#fff\">mini-app</div></div>\n<div style=\"text-align:right\"><div id=\"score\" style=\"font-size:18px;font-weight:bold;color:#fff;text-shadow:0 0 10px rgba(108,92,231,.85);transition:transform .15s\">00000</div><div id=\"best\" style=\"font-size:10px;color:rgba(255,255,255,.4);margin-top:2px\">BEST 00000</div></div>\n</div>\n<div style=\"padding:18px\">\n<canvas id=\"game\" width=\"560\" height=\"190\" style=\"width:100%;height:auto;background:rgba(255,255,255,.03);border:1px solid rgba(255,255,255,.12);border-radius:12px;display:block\"></canvas>\n<div id=\"status\" style=\"text-align:center;margin-top:10px;font-size:12px;color:rgba(255,255,255,.55)\">Velocità 5.0x</div>\n</div></div></div>\n<script>\nconst c=document.getElementById('game'),x=c.getContext('2d'),scoreEl=document.getElementById('score'),bestEl=document.getElementById('best'),statusEl=document.getElementById('status');\nconst GY=170;\nlet d,o,clouds,particles,ambient,trail,score,best=0,speed,gameOver,last,shake,flash,runT,spawnTimer,milestone,squash;\nfunction loadBest(){\nlet vals=[];\ntry{let v=localStorage.getItem('dino_best');if(v)vals.push(parseInt(v,10))}catch(e){}\ntry{let v=sessionStorage.getItem('dino_best');if(v)vals.push(parseInt(v,10))}catch(e){}\ntry{let m=document.cookie.match(/(?:^|;\\s*)dino_best=(\\d+)/);if(m)vals.push(parseInt(m[1],10))}catch(e){}\nreturn vals.length?Math.max(...vals.filter(v=>!isNaN(v))):0\n}\nfunction saveBest(v){\nlet val=String(Math.floor(v));\ntry{localStorage.setItem('dino_best',val)}catch(e){}\ntry{sessionStorage.setItem('dino_best',val)}catch(e){}\ntry{document.cookie='dino_best='+val+';max-age=31536000;path=/'}catch(e){}\ntry{\nlet rq=indexedDB.open('dino_db',1);\nrq.onupgradeneeded=()=>{rq.result.createObjectStore('kv')};\nrq.onsuccess=()=>{try{rq.result.transaction('kv','readwrite').objectStore('kv').put(val,'dino_best')}catch(e){}}\n}catch(e){}\n}\nfunction loadBestAsync(cb){\ntry{\nlet rq=indexedDB.open('dino_db',1);\nrq.onupgradeneeded=()=>{rq.result.createObjectStore('kv')};\nrq.onsuccess=()=>{\ntry{\nlet gr=rq.result.transaction('kv','readonly').objectStore('kv').get('dino_best');\ngr.onsuccess=()=>{if(gr.result)cb(parseInt(gr.result,10))}\n}catch(e){}\n}\n}catch(e){}\n}\nbest=loadBest();\nloadBestAsync(v=>{if(!isNaN(v)&&v>best){best=v;bestEl.textContent='BEST '+String(Math.floor(best)).padStart(5,'0')}});\nfunction reset(){\nd={x:55,y:132,w:27,h:30,vy:0,jumping:false};\no=[];\nclouds=[{x:120,y:32,w:44,s:.35},{x:300,y:52,w:60,s:.22},{x:460,y:26,w:36,s:.4},{x:560,y:70,w:50,s:.18}];\nparticles=[];\ntrail=[];\nif(!ambient){ambient=[];for(let i=0;i<18;i++)ambient.push({x:Math.random()*c.width,y:Math.random()*c.height,r:.5+Math.random()*1.5,vx:.1+Math.random()*.3,ph:Math.random()*10})}\nscore=0;speed=5;gameOver=false;last=0;shake=0;flash=0;runT=0;milestone=0;squash=1;\nspawnTimer=70+Math.random()*30;\nbestEl.textContent='BEST '+String(Math.floor(best)).padStart(5,'0');\nstatusEl.textContent='Speed 5.0x'\n}\nfunction burst(px,py,n,col,spd){for(let i=0;i<n;i++)particles.push({x:px,y:py,vx:(Math.random()-.5)*spd,vy:-Math.random()*spd,life:1,col,size:2+Math.random()*2})}\nfunction jumpDino(){\nif(gameOver){reset();return}\nif(!d.jumping){d.jumping=true;d.vy=-13;squash=.7;burst(d.x+13,d.y+30,10,'255,255,255',4)}\n}\nfunction cactus(){\nlet h=24+Math.random()*24;\no.push({x:c.width+20,y:GY-h,w:16+Math.random()*6,h});\nif(Math.random()<.22){o.push({x:c.width+20+34+Math.random()*10,y:GY-(20+Math.random()*18),w:16,h:20+Math.random()*18})}\n}\nfunction hit(a,b){return a.x+4<b.x+b.w&&a.x+a.w-4>b.x&&a.y+4<b.y+b.h&&a.y+a.h>b.y}\nfunction drawTrail(){\ntrail.forEach((p,i)=>{x.fillStyle='rgba(108,92,231,'+(.25*(i/trail.length))+')';x.fillRect(p.x,p.y,27,30)})\n}\nfunction drawDino(){\nx.save();\nlet cx=d.x+13,cy=d.y+30;\nx.translate(cx,cy);\nx.scale(1/squash,squash);\nx.translate(-cx,-cy);\nlet legOff=d.jumping?0:Math.sin(runT*.5)*5;\nx.fillStyle='#eaeaea';\nx.fillRect(d.x,d.y,27,30);\nx.fillRect(d.x+22,d.y+5,13,18);\nx.fillStyle='#6c5ce7';\nx.fillRect(d.x+29,d.y+8,4,4);\nx.fillStyle='#eaeaea';\nx.fillRect(d.x+5,d.y+30,6,8+legOff);\nx.fillRect(d.x+20,d.y+30,6,8-legOff);\nx.restore()\n}\nfunction drawCactus(q){\nx.save();\nx.shadowColor='rgba(255,90,90,.35)';x.shadowBlur=10;\nx.fillStyle='#e17a7a';\nx.fillRect(q.x,q.y,q.w,q.h);\nx.fillRect(q.x-7,q.y+10,7,6);\nx.fillRect(q.x-7,q.y+4,6,12);\nx.fillRect(q.x+q.w,q.y+18,7,6);\nx.fillRect(q.x+q.w+1,q.y+12,6,12);\nx.restore()\n}\nfunction drawParticles(){\nparticles.forEach(p=>{x.fillStyle='rgba('+p.col+','+Math.max(p.life,0)+')';x.fillRect(p.x,p.y,p.size,p.size)})\n}\nfunction drawAmbient(){\nambient.forEach(p=>{let a=.15+Math.sin(runT*.05+p.ph)*.1;x.fillStyle='rgba(180,160,255,'+a+')';x.beginPath();x.arc(p.x,p.y,p.r,0,7);x.fill()})\n}\nfunction draw(){\nx.clearRect(0,0,c.width,c.height);\nx.save();\nif(shake>0)x.translate((Math.random()-.5)*shake,(Math.random()-.5)*shake);\ndrawAmbient();\nx.fillStyle='rgba(255,255,255,.35)';\nclouds.forEach(q=>{let b=Math.sin(runT*.03+q.x)*2;x.fillRect(q.x,q.y+b,q.w,5);x.fillRect(q.x+10,q.y+b-5,q.w*.45,10)});\nx.strokeStyle='rgba(255,255,255,.25)';\nx.lineWidth=2;\nx.setLineDash([10,8]);\nx.lineDashOffset=-runT*speed*.6;\nx.beginPath();x.moveTo(0,GY);x.lineTo(c.width,GY);x.stroke();\nx.setLineDash([]);\ndrawTrail();\ndrawDino();\no.forEach(drawCactus);\ndrawParticles();\nif(flash>0){x.fillStyle='rgba(255,60,60,'+(flash*.35)+')';x.fillRect(0,0,c.width,c.height)}\nx.restore();\nif(gameOver){\nx.fillStyle='rgba(15,15,25,.55)';x.fillRect(0,0,c.width,c.height);\nx.fillStyle='#fff';x.textAlign='center';\nx.font='bold 24px Arial';x.fillText('GAME OVER',c.width/2,85);\nx.font='14px Arial';x.fillText('Tocca per giocare di nuovo',c.width/2,112);\nx.textAlign='left'\n}\n}\nfunction loop(t){\nif(!last)last=t;\nlet dt=Math.min((t-last)/16.67,2);\nlast=t;\nrunT+=dt;\nif(!gameOver){\nd.y+=d.vy*dt;d.vy+=.75*dt;\nif(d.y>=132){\nif(d.jumping){burst(d.x+13,GY,10,'255,255,255',3.5);squash=1.35}\nd.y=132;d.vy=0;d.jumping=false\n}\nif(d.jumping)trail.push({x:d.x,y:d.y});\nif(trail.length>6)trail.shift();\nif(!d.jumping)trail.length=0;\nsquash+=(1-squash)*.18*dt;\nif(!d.jumping&&Math.floor(runT)%8===0&&Math.random()<.4)burst(d.x+6,GY-2,1,'255,255,255',1.5);\nambient.forEach(p=>{p.x-=p.vx*dt;if(p.x<-4)p.x=c.width+4});\nspawnTimer-=dt;\nif(spawnTimer<=0){cactus();spawnTimer=Math.max(38,62-speed*1.4)+Math.random()*30}\no.forEach(q=>q.x-=speed*dt);\no=o.filter(q=>q.x>-40);\nclouds.forEach(q=>{q.x-=q.s*dt;if(q.x<-80)q.x=c.width+Math.random()*100});\nparticles.forEach(p=>{p.x+=p.vx*dt;p.y+=p.vy*dt;p.vy+=.3*dt;p.life-=.03*dt});\nparticles=particles.filter(p=>p.life>0);\nspeed=Math.min(11,speed+.0018*dt);\nscore+=dt*.6;\nif(score>best)best=score;\nif(Math.floor(score/500)>milestone){\nmilestone=Math.floor(score/500);\nscoreEl.style.transform='scale(1.35)';\nsetTimeout(()=>scoreEl.style.transform='scale(1)',150)\n}\nscoreEl.textContent=String(Math.floor(score)).padStart(5,'0');\nbestEl.textContent='BEST '+String(Math.floor(best)).padStart(5,'0');\nstatusEl.textContent='Speed '+speed.toFixed(1)+'x';\nfor(const q of o)if(hit(d,q)){\ngameOver=true;shake=14;flash=1;\nsaveBest(best);\nburst(d.x+13,d.y+15,18,'255,90,90',5)\n}\n}\nif(shake>0)shake=Math.max(0,shake-.6*dt);\nif(flash>0)flash=Math.max(0,flash-.05*dt);\ndraw();\nrequestAnimationFrame(loop)\n}\ndocument.addEventListener('pointerdown',e=>{e.preventDefault();jumpDino()});\ndocument.addEventListener('keydown',e=>{if(e.code==='Space'){e.preventDefault();jumpDino()}});\nreset();\nrequestAnimationFrame(loop);\n</script></body>";
|
|
16
|
+
return options.title ? html.replace('mini-app', String(options.title)) : html;
|
|
17
|
+
};
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @X4R1S3
|
|
3
|
+
*
|
|
4
|
+
* File: lib/Utils/games/slot-machine.js
|
|
5
|
+
* About: Slot machine module for the X4R1S3 WhatsApp protocol client.
|
|
6
|
+
* Important exports: generateSlotMachineHtml, prepareSlotMachineMessage
|
|
7
|
+
* Directions: Import the listed exports and preserve protocol, validation, and compatibility invariants when modifying.
|
|
8
|
+
*
|
|
9
|
+
* Copyright and attribution notice.
|
|
10
|
+
* Do not copy, reproduce, redistribute, modify, or create derivative works
|
|
11
|
+
* from this source without explicit written permission.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Slot Machine Game — Fruit Bonanza
|
|
15
|
+
*
|
|
16
|
+
* A complete canvas-based slot machine game that renders directly
|
|
17
|
+
* inside WhatsApp chat bubbles using FOAHtmlPrimitiveDemoDONOTUSE.
|
|
18
|
+
*
|
|
19
|
+
* Features:
|
|
20
|
+
* - 5 reels with Cherry, Lemon, Bell, Diamond, 7, BAR symbols
|
|
21
|
+
* - Betting system (10/20/50 credits)
|
|
22
|
+
* - Win detection with 5 paylines
|
|
23
|
+
* - Canvas-rendered symbols with animations
|
|
24
|
+
* - Jungle/green theme
|
|
25
|
+
* - Lever animation
|
|
26
|
+
* - Jackpot display & game over screen
|
|
27
|
+
*
|
|
28
|
+
* Usage:
|
|
29
|
+
* const { generateSlotMachineHtml } = require('./slot-machine');
|
|
30
|
+
* const html = generateSlotMachineHtml();
|
|
31
|
+
* await sock.sendHtmlMessage(jid, { html });
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
const SLOT_MACHINE_HTML = `<html><head><style>
|
|
35
|
+
*{box-sizing:border-box}html,body{margin:0;width:100%;overflow:hidden;background:transparent;font-family:Arial,sans-serif;overscroll-behavior:none}body{padding:9px;background:radial-gradient(circle at 50% 12%,#5b2d18,#160908 55%,#030202)}.machine{position:relative;overflow:hidden;padding:13px 34px 18px 13px;border:4px solid #2b0c05;border-radius:30px;background:linear-gradient(105deg,#1e0704,#8c3515 8%,#3b1008 20%,#611e0c 52%,#2b0906 82%,#9c401b 94%,#2a0b06);box-shadow:inset 0 0 0 3px #e6a139,inset 0 0 0 7px #5d210b,inset 0 20px 35px #ffb52a22,0 8px 0 #210705,0 14px 24px #000c;touch-action:none}.machine:before{content:"";position:absolute;inset:8px;border:2px solid #ffba3d;border-radius:22px;pointer-events:none;box-shadow:inset 0 0 11px #ff7b00}.lights{height:9px;margin:0 14px 8px;border:2px solid #6f2608;border-radius:8px;background:repeating-radial-gradient(circle at 6px 50%,#fffbd3 0 2px,#ffbd00 3px 5px,#641800 6px 12px);box-shadow:0 0 12px #ff8a00;animation:lights .55s steps(2) infinite}.title{padding:11px 4px 8px;border:3px solid #ffc54c;border-radius:50% 50% 11px 11px/30% 30% 10px 10px;color:#fff2a1;background:radial-gradient(ellipse at 50% 0,#12b2bc,#075165 58%,#06182a);box-shadow:inset 0 0 0 4px #74300d,inset 0 -11px 18px #001726,0 4px 0 #3b1207;text-align:center;font:25px Impact,Arial Black,sans-serif;letter-spacing:1px;text-shadow:0 3px #8f1c0c,2px 0 #8f1c0c,-2px 0 #8f1c0c}.jackpot{width:75%;margin:5px auto 8px;padding:4px;border:2px solid #ffcf5b;border-radius:10px;color:#ffe7a1;background:linear-gradient(#741523,#29060e);box-shadow:inset 0 2px 5px #ff667744;text-align:center;font:bold 10px monospace;letter-spacing:1px}.stats{display:flex;margin:0 2px 9px;padding:5px;border:2px solid #b66b20;border-radius:9px;background:linear-gradient(#210c08,#070303);box-shadow:inset 0 0 9px #000,0 3px 0 #4a1909}.stat{flex:1;border-right:1px solid #754016;color:#d6a15b;text-align:center;font:bold 10px monospace}.stat:last-child{border:0}.stat b{display:block;margin-top:2px;color:#fff0bb;font-size:15px;text-shadow:0 0 6px #f80}.frame{position:relative;padding:9px;border:5px solid #9b4e12;border-radius:18px;background:linear-gradient(90deg,#4b1c08,#ffd873 5%,#6a2709 10%,#6a2709 90%,#ffd873 95%,#421506);box-shadow:inset 0 0 0 3px #2b0d05,0 4px 0 #301005,0 8px 15px #000b}.reelbox{position:relative;display:grid;grid-template-columns:repeat(5,1fr);height:192px;overflow:hidden;border:3px solid #1d0804;border-radius:11px;background:#140604;box-shadow:inset 0 13px 20px #000,inset 0 -13px 20px #000}.reel{position:relative;overflow:hidden;border-right:2px solid #6e421e;background:linear-gradient(90deg,#a58149,#fffce4 17%,#fffdf0 50%,#f7e9bd 82%,#8e6a38);box-shadow:inset 7px 0 8px #573b1d66,inset -7px 0 8px #573b1d66}.reel:last-child{border:0}.reel:after{content:"";position:absolute;z-index:2;inset:0;pointer-events:none;background:linear-gradient(#3b1d0fbb 0,transparent 18%,transparent 80%,#281208cc 100%);box-shadow:inset 0 9px 11px #0005,inset 0 -9px 11px #0005}.strip{position:absolute;left:0;right:0;top:0;transform:translate3d(0,0,0);will-change:transform,filter}.strip.moving{filter:blur(1.4px) saturate(1.2)}.sym{height:64px;display:grid;place-items:center;border-bottom:1px solid #9f7e4f66;color:#d30f1c;font-family:Apple Color Emoji,Segoe UI Emoji,Arial Black,sans-serif;font-size:clamp(26px,8vw,40px);line-height:1;text-shadow:0 3px 0 #721018,0 0 4px #fff;transform:translateZ(0)}.sym.s4{font:900 42px Impact,Arial Black,sans-serif;color:#ef1726;-webkit-text-stroke:2px #850815;text-shadow:0 3px #5d0509,0 0 5px #fff}.sym.s5{font:900 16px Arial Black,sans-serif;color:#fff4c4;background:radial-gradient(ellipse at center,#e22d35 0,#6f0910 52%,transparent 54%);text-shadow:0 2px #401010}.sym.win{animation:win .5s ease-in-out infinite;background:radial-gradient(circle,#fff8a9,#ffae00 55%,transparent 72%)}.shine{position:absolute;z-index:3;inset:4px 8% 55%;border-radius:50%;background:linear-gradient(#fff7,transparent);pointer-events:none}.payline{position:absolute;z-index:4;left:9px;right:9px;height:3px;opacity:0;background:#fff5a1;box-shadow:0 0 7px #fff,0 0 14px #ff3d00;pointer-events:none}.payline.on{animation:line 1s ease infinite}.p0{top:20%}.p1{top:50%}.p2{top:80%}.message{height:34px;margin:9px 2px 7px;display:grid;place-items:center;border:2px solid #a55c19;border-radius:8px;color:#ffd46a;background:#150504;box-shadow:inset 0 0 8px #000;text-align:center;font:bold 14px monospace;text-shadow:0 0 7px #f60}.console{display:grid;grid-template-columns:1fr 1.7fr;gap:8px;margin:0 3px;padding:10px 9px 13px;border:3px solid #8e4914;border-radius:9px 9px 17px 17px;background:linear-gradient(#d69a49,#63300f 37%,#2a0b06 39%,#4b1509);box-shadow:inset 0 2px #ffe0a0,0 5px #1c0704,0 9px 12px #0008;transform:perspective(300px) rotateX(4deg)}button{height:53px;border:3px solid #351006;border-radius:13px;color:#fff;font-weight:900;touch-action:none}.bet{background:linear-gradient(#42c4df,#086184 53%,#03334c);box-shadow:inset 0 4px 4px #fff8,0 4px #051e2a}.spin{background:radial-gradient(circle at 50% 32%,#8aff77,#20a72d 47%,#075b17 76%);box-shadow:inset 0 4px 5px #e3ffdc,0 4px #07350e,0 0 14px #3cff4a;font-size:18px;text-shadow:0 2px #06420d}.tray{width:49%;height:19px;margin:14px auto 0;border:4px solid #48200b;border-radius:4px 4px 10px 10px;background:#090303;box-shadow:inset 0 6px 9px #000,0 3px #c47c29}.leverTrack{position:absolute;z-index:5;right:9px;top:211px;width:20px;height:150px;border:2px solid #3d1809;border-radius:13px;background:linear-gradient(90deg,#321006,#df9a39,#52200a);box-shadow:inset 0 0 5px #000}.lever{position:absolute;left:-4px;top:8px;width:28px;height:112px;transform-origin:50% 88%;transition:transform .34s cubic-bezier(.2,.8,.2,1);touch-action:none}.lever:before{content:"";position:absolute;left:11px;top:17px;width:7px;height:86px;border:2px solid #333;border-radius:4px;background:linear-gradient(90deg,#444,#fff 48%,#666 64%,#222)}.lever:after{content:"";position:absolute;left:0;width:29px;height:29px;border:3px solid #650000;border-radius:50%;background:radial-gradient(circle at 35% 25%,#fff,#ff7777 13%,#ed1720 37%,#850007 74%);box-shadow:inset -5px -6px 7px #490000,0 4px 5px #000,0 0 9px #f22}.lever.pull{transform:rotate(36deg)}.over{position:absolute;z-index:10;inset:0;display:grid;place-items:center;text-align:center;color:#ffe5a0;background:#080100ed}.over.off{display:none}.over h2{margin:0 0 8px;color:#ff3449;text-shadow:0 0 12px #f00}.over button{padding:0 22px;background:#ffd15a;color:#271204}@keyframes lights{50%{filter:brightness(1.7)}}@keyframes win{50%{transform:scale(1.09);filter:brightness(1.4)}}@keyframes line{50%{opacity:1}}
|
|
36
|
+
</style><style>.reelbox{display:block;height:205px;padding:0;background:#160704}
|
|
37
|
+
#reelCanvas{display:block;width:100%;height:100%;border-radius:8px;touch-action:none}
|
|
38
|
+
</style><style>body{padding:15px 13px 29px;perspective:950px}
|
|
39
|
+
.machine{transform-origin:50% 88%;transform:perspective(850px) rotateX(1.2deg) translateZ(0);box-shadow:inset 0 0 0 3px #f0b64b,inset 0 0 0 8px #501708,inset 14px 0 24px #ffb3421f,inset -15px 0 25px #16030199,0 9px 0 #180503,0 17px 0 #421508,0 27px 35px #000e}
|
|
40
|
+
.machine:after{content:"";position:absolute;z-index:-2;left:7%;right:7%;bottom:-30px;height:30px;border-radius:50%;background:radial-gradient(ellipse,#000d 0,#0008 42%,transparent 73%);filter:blur(4px)}
|
|
41
|
+
.title{transform:perspective(500px) rotateX(-3deg) translateZ(8px);box-shadow:inset 0 0 0 4px #74300d,inset 0 -13px 20px #001522,0 5px 0 #351006,0 10px 16px #0009}
|
|
42
|
+
.frame{transform:perspective(650px) rotateX(-1.5deg) translateZ(7px);box-shadow:inset 0 0 0 3px #2b0d05,inset 0 12px 13px #fff2b21c,0 6px 0 #291006,0 13px 19px #000c}
|
|
43
|
+
.console{transform:perspective(420px) rotateX(8deg) translateZ(5px);transform-origin:50% 0;box-shadow:inset 0 3px #ffe4ac,0 7px #1b0704,0 15px 20px #000b}
|
|
44
|
+
.machine.charging{animation:crateCharge .56s cubic-bezier(.36,.07,.19,.97) both}
|
|
45
|
+
.machine.charging .lights{animation:warningFlash .12s steps(2) infinite}
|
|
46
|
+
.machine.charging .frame{animation:frameTension .56s ease both}
|
|
47
|
+
.machine.charging .title{animation:signTension .56s ease both}
|
|
48
|
+
@keyframes crateCharge{0%{transform:perspective(850px) rotateX(1.2deg) rotateZ(0) translate(0,0) scale(1)}12%{transform:perspective(850px) rotateX(2deg) rotateZ(-.8deg) translate(-2px,1px) scale(.995)}25%{transform:perspective(850px) rotateX(.2deg) rotateZ(1deg) translate(3px,-1px) scale(1.008)}39%{transform:perspective(850px) rotateX(2.2deg) rotateZ(-1.15deg) translate(-3px,1px) scale(.998)}52%{transform:perspective(850px) rotateX(.3deg) rotateZ(.9deg) translate(3px,-2px) scale(1.012)}66%{transform:perspective(850px) rotateX(2deg) rotateZ(-.55deg) translate(-2px,1px) scale(1.004)}79%{transform:perspective(850px) rotateX(.7deg) rotateZ(.35deg) translate(1px,-1px) scale(1.01)}100%{transform:perspective(850px) rotateX(1.2deg) rotateZ(0) translate(0,0) scale(1)}}
|
|
49
|
+
@keyframes warningFlash{50%{filter:brightness(2.2) saturate(1.8);box-shadow:0 0 21px #ffca28}}
|
|
50
|
+
@keyframes frameTension{45%{transform:perspective(650px) rotateX(-2.5deg) translateZ(13px) scale(1.012)}100%{transform:perspective(650px) rotateX(-1.5deg) translateZ(7px)}}
|
|
51
|
+
@keyframes signTension{45%{transform:perspective(500px) rotateX(-5deg) translateZ(15px)}100%{transform:perspective(500px) rotateX(-3deg) translateZ(8px)}}
|
|
52
|
+
</style><style>.machine.charging{animation:leverDip .28s cubic-bezier(.25,.8,.25,1) both}
|
|
53
|
+
.machine.charging .frame,.machine.charging .title{animation:none}
|
|
54
|
+
.machine.reelKick{animation:reelKick .13s cubic-bezier(.2,.8,.3,1)}
|
|
55
|
+
@keyframes leverDip{0%{transform:perspective(850px) rotateX(1.2deg) translateY(0) scale(1)}42%{transform:perspective(850px) rotateX(2.4deg) translateY(3px) scale(.994)}72%{transform:perspective(850px) rotateX(.5deg) translateY(-2px) scale(1.004)}100%{transform:perspective(850px) rotateX(1.2deg) translateY(0) scale(1)}}
|
|
56
|
+
@keyframes reelKick{0%{transform:perspective(850px) rotateX(1.2deg) translateX(0)}35%{transform:perspective(850px) rotateX(1.7deg) translateX(-1.5px) translateY(1px)}70%{transform:perspective(850px) rotateX(.8deg) translateX(1px) translateY(-1px)}100%{transform:perspective(850px) rotateX(1.2deg) translateX(0)}}
|
|
57
|
+
</style><style>.machine.charging,.machine.reelKick{animation:none!important}
|
|
58
|
+
.machine.charging .frame,.machine.charging .title,.machine.charging .lights{animation:none!important}
|
|
59
|
+
.leverTrack{right:9px;top:211px;width:24px;height:158px;overflow:hidden;border-radius:12px}
|
|
60
|
+
.lever{left:0;top:7px;width:24px;height:100px;transform:none;transform-origin:50% 50%;transition:transform .3s cubic-bezier(.2,.8,.2,1)}
|
|
61
|
+
.lever:before{left:8px;top:18px;width:7px;height:77px}
|
|
62
|
+
.lever:after{left:0;top:0;width:24px;height:24px;border-width:2px}
|
|
63
|
+
.lever.pull{transform:translateY(47px)}
|
|
64
|
+
</style><style>
|
|
65
|
+
/* Fixed-pivot lever: the mount stays still; only the arm swings. */
|
|
66
|
+
.machine{
|
|
67
|
+
padding-right:70px!important;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.leverTrack{
|
|
71
|
+
position:absolute!important;
|
|
72
|
+
right:8px!important;
|
|
73
|
+
top:205px!important;
|
|
74
|
+
width:56px!important;
|
|
75
|
+
height:150px!important;
|
|
76
|
+
overflow:hidden!important;
|
|
77
|
+
border-radius:16px!important;
|
|
78
|
+
transform:none!important;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.leverTrack:after{
|
|
82
|
+
content:"";
|
|
83
|
+
position:absolute;
|
|
84
|
+
left:2px;
|
|
85
|
+
bottom:1px;
|
|
86
|
+
width:27px;
|
|
87
|
+
height:27px;
|
|
88
|
+
z-index:3;
|
|
89
|
+
border:2px solid #5b2509;
|
|
90
|
+
border-radius:50%;
|
|
91
|
+
box-sizing:border-box;
|
|
92
|
+
background:radial-gradient(circle at 35% 30%,#fff6c8 0 8%,#f7bd3d 9% 25%,#9b3d08 52%,#3a1205 76%);
|
|
93
|
+
box-shadow:inset 0 0 0 3px #ffda67,0 2px 5px #000b;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.lever{
|
|
97
|
+
position:absolute!important;
|
|
98
|
+
left:2px!important;
|
|
99
|
+
top:auto!important;
|
|
100
|
+
bottom:9px!important;
|
|
101
|
+
width:27px!important;
|
|
102
|
+
height:105px!important;
|
|
103
|
+
transform:rotate(0deg)!important;
|
|
104
|
+
transform-origin:13.5px 95px!important;
|
|
105
|
+
transition:transform .34s cubic-bezier(.2,.88,.25,1.08)!important;
|
|
106
|
+
z-index:2!important;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
.lever:before{
|
|
110
|
+
left:10px!important;
|
|
111
|
+
top:18px!important;
|
|
112
|
+
width:7px!important;
|
|
113
|
+
height:80px!important;
|
|
114
|
+
border-radius:5px!important;
|
|
115
|
+
background:linear-gradient(90deg,#321003 0,#f3c56f 20%,#fff5cf 43%,#9b4c18 72%,#260b02 100%)!important;
|
|
116
|
+
box-shadow:0 2px 4px #000b!important;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.lever:after{
|
|
120
|
+
left:1px!important;
|
|
121
|
+
top:0!important;
|
|
122
|
+
width:24px!important;
|
|
123
|
+
height:24px!important;
|
|
124
|
+
border-width:2px!important;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.lever.pull{
|
|
128
|
+
transform:rotate(17deg)!important;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
</style><style>
|
|
132
|
+
/* Front-facing pull: fixed lower pivot with perspective foreshortening. */
|
|
133
|
+
.lever{
|
|
134
|
+
transform:none!important;
|
|
135
|
+
transform-origin:50% 100%!important;
|
|
136
|
+
transition:none!important;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.lever:before{
|
|
140
|
+
transform:scaleY(1)!important;
|
|
141
|
+
transform-origin:50% 100%!important;
|
|
142
|
+
transition:transform .34s cubic-bezier(.2,.85,.25,1)!important;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
.lever:after{
|
|
146
|
+
transform:translateY(0) scale(1)!important;
|
|
147
|
+
transform-origin:50% 50%!important;
|
|
148
|
+
transition:transform .34s cubic-bezier(.2,.85,.25,1.08)!important;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
.lever.pull{
|
|
152
|
+
transform:none!important;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
.lever.pull:before{
|
|
156
|
+
transform:scaleY(.56)!important;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.lever.pull:after{
|
|
160
|
+
transform:translateY(36px) scale(1.16)!important;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
</style><style>
|
|
164
|
+
/* Rigid front-pulling lever assembly. */
|
|
165
|
+
.machine{padding-right:62px!important}
|
|
166
|
+
.leverTrack{right:8px!important;top:205px!important;width:47px!important;height:150px!important;overflow:hidden!important}
|
|
167
|
+
.leverTrack:after{left:9px!important;bottom:5px!important;width:27px!important;height:27px!important;z-index:4!important}
|
|
168
|
+
.lever{left:0!important;right:0!important;bottom:12px!important;top:auto!important;width:100%!important;height:112px!important;transform:none!important}
|
|
169
|
+
.lever:before,.lever:after{display:none!important}
|
|
170
|
+
.leverArm{position:absolute;left:20px;bottom:7px;width:7px;height:91px;border:2px solid #292929;border-radius:5px;box-sizing:border-box;background:linear-gradient(90deg,#3c3c3c,#fff 43%,#8a8a8a 68%,#252525);box-shadow:0 2px 4px #000b;transform:scaleY(1);transform-origin:50% 100%;transition:transform .34s cubic-bezier(.2,.82,.25,1)}
|
|
171
|
+
.leverKnob{position:absolute;left:-10px;top:-13px;width:27px;height:27px;border:3px solid #650000;border-radius:50%;box-sizing:border-box;background:radial-gradient(circle at 35% 25%,#fff,#ff7777 13%,#ed1720 37%,#850007 74%);box-shadow:inset -5px -6px 7px #490000,0 4px 5px #000,0 0 9px #f22;transform:scaleY(1) scale(1);transition:transform .34s cubic-bezier(.2,.82,.25,1)}
|
|
172
|
+
.lever.pull .leverArm{transform:scaleY(.52)}
|
|
173
|
+
.lever.pull .leverKnob{transform:scaleY(1.9231) scale(1.12)}
|
|
174
|
+
|
|
175
|
+
</style><style>
|
|
176
|
+
.leverTrack{display:none!important}
|
|
177
|
+
html,body{min-height:0!important}
|
|
178
|
+
body{padding:4px!important}
|
|
179
|
+
.machine{padding:8px 10px 10px!important;border-width:3px!important;border-radius:22px!important;box-shadow:inset 0 0 0 2px #e6a139,inset 0 0 0 5px #5d210b,inset 0 14px 25px #ffb52a22,0 5px 0 #210705,0 9px 16px #000c!important}
|
|
180
|
+
.machine:before{inset:6px!important;border-radius:17px!important}
|
|
181
|
+
.lights{height:7px!important;margin:0 12px 5px!important}
|
|
182
|
+
.title{padding:7px 4px 5px!important;font-size:21px!important}
|
|
183
|
+
.jackpot{margin:3px auto 5px!important;padding:3px!important}
|
|
184
|
+
.stats{margin:0 2px 6px!important;padding:4px!important}
|
|
185
|
+
.stat b{font-size:13px!important;margin-top:1px!important}
|
|
186
|
+
.frame{padding:6px!important;border-width:4px!important;border-radius:14px!important}
|
|
187
|
+
.reelbox{height:150px!important;border-radius:9px!important}
|
|
188
|
+
.message{height:29px!important;margin:6px 2px 5px!important;font-size:12px!important}
|
|
189
|
+
.console{gap:7px!important;margin:0 3px!important;padding:7px 8px 9px!important}
|
|
190
|
+
button{height:44px!important}
|
|
191
|
+
.spin{font-size:16px!important}
|
|
192
|
+
.tray{height:14px!important;margin-top:9px!important;border-width:3px!important}
|
|
193
|
+
|
|
194
|
+
</style><style>
|
|
195
|
+
body{background:radial-gradient(circle at 50% 8%,#1d6a50,#0f4938 48%,#07291f)!important}
|
|
196
|
+
.machine{border-color:#071f18!important;background:linear-gradient(110deg,#061e17,#1b644b 10%,#0b382a 24%,#15543f 54%,#092f24 82%,#28775a 94%,#071f18)!important;box-shadow:inset 0 0 0 2px #b9954d,inset 0 0 0 5px #163f31,inset 0 14px 24px #73d2a31c,0 5px 0 #041a13,0 9px 16px #000b!important}
|
|
197
|
+
.machine:before{border-color:#b59349!important;box-shadow:inset 0 0 9px #4fa57a66!important}
|
|
198
|
+
.lights{border-color:#123d2f!important;background:repeating-radial-gradient(circle at 6px 50%,#dfffdc 0 2px,#82c878 3px 5px,#164936 6px 12px)!important;box-shadow:0 0 9px #67b881!important}
|
|
199
|
+
.title{border-color:#b99a54!important;color:#e9e3bc!important;background:radial-gradient(ellipse at 50% 0,#2b8a6c,#11513f 58%,#082a24)!important;box-shadow:inset 0 0 0 4px #244f3d,inset 0 -10px 17px #061e19,0 4px 0 #071d16!important;text-shadow:0 2px #193f31,2px 0 #193f31,-2px 0 #193f31!important}
|
|
200
|
+
.jackpot{border-color:#a98c4d!important;color:#ded7ad!important;background:linear-gradient(#245d48,#0b3025)!important;box-shadow:inset 0 2px 5px #8ed3a233!important}
|
|
201
|
+
.stats,.message{border-color:#537d64!important;background:linear-gradient(#102d24,#061812)!important}
|
|
202
|
+
.stat{border-color:#416452!important;color:#91b59f!important}.stat b,.message{color:#e3dfbb!important;text-shadow:0 0 6px #62a77d!important}
|
|
203
|
+
.frame{border-color:#315c47!important;background:linear-gradient(90deg,#09271e,#b49a59 5%,#174936 10%,#174936 90%,#b49a59 95%,#09271e)!important;box-shadow:inset 0 0 0 3px #071b15,0 4px 0 #09271e,0 8px 15px #000a!important}
|
|
204
|
+
.reelbox{border-color:#071c15!important;background:#071a14!important;box-shadow:inset 0 9px 15px #0009,inset 0 -9px 15px #0009!important}
|
|
205
|
+
.shine{display:none!important}
|
|
206
|
+
.console{border-color:#416a53!important;background:linear-gradient(#9c8c59,#315d48 37%,#0a2e22 39%,#123e2f)!important;box-shadow:inset 0 2px #d9c992,0 5px #061d16,0 9px 12px #0008!important}
|
|
207
|
+
.bet{background:linear-gradient(#4f9a77,#216348 53%,#103d2d)!important;box-shadow:inset 0 4px 4px #d8ffe055,0 4px #092a20!important}
|
|
208
|
+
.spin{background:radial-gradient(circle at 50% 32%,#a8d96f,#4b8d46 47%,#1e542f 76%)!important;box-shadow:inset 0 4px 5px #e8ffd488,0 4px #12351e,0 0 12px #79b85c88!important}
|
|
209
|
+
.tray{border-color:#244d3a!important;background:#061a13!important;box-shadow:inset 0 6px 9px #000,0 3px #897945!important}
|
|
210
|
+
|
|
211
|
+
</style><style>
|
|
212
|
+
.payline{height:3px!important;background:linear-gradient(90deg,transparent,#dfff8a 18%,#fff5b0 50%,#7fe091 82%,transparent)!important;box-shadow:0 0 7px #efffa8,0 0 15px #65c984!important;transform:scaleX(.15);transform-origin:50% 50%}
|
|
213
|
+
.payline.on{opacity:1!important;animation:jungleLine 1.15s cubic-bezier(.2,.8,.2,1) infinite!important}
|
|
214
|
+
.machine.winner .message{animation:jungleDisplay .7s ease-in-out 2!important}
|
|
215
|
+
.machine.winner .lights{animation:jungleLights .22s steps(2) 6!important}
|
|
216
|
+
.machine.winner .title{animation:jungleTitle .7s ease-in-out 2!important}
|
|
217
|
+
@keyframes jungleLine{0%{transform:scaleX(.08);filter:brightness(1)}45%{transform:scaleX(1);filter:brightness(1.8)}75%,100%{transform:scaleX(1);opacity:0}}
|
|
218
|
+
@keyframes jungleDisplay{50%{color:#fff8bd;box-shadow:inset 0 0 14px #7ddc8a,0 0 13px #74ce82;filter:brightness(1.35)}}
|
|
219
|
+
@keyframes jungleLights{50%{filter:brightness(2.2) saturate(1.4)}}
|
|
220
|
+
@keyframes jungleTitle{50%{filter:brightness(1.35);text-shadow:0 0 12px #cfff91,0 2px #193f31}}
|
|
221
|
+
|
|
222
|
+
</style><style>
|
|
223
|
+
.machine{
|
|
224
|
+
box-shadow:inset 0 0 0 2px #b9954d,inset 0 0 0 5px #163f31,inset 0 14px 24px #73d2a31c!important;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
</style><style>
|
|
228
|
+
html,body{width:100%!important}
|
|
229
|
+
body{padding:0!important}
|
|
230
|
+
.machine{width:100%!important;margin:0!important}
|
|
231
|
+
|
|
232
|
+
</style></head><body><div class="machine" id="machine"><div class="lights"></div><div class="title">FRUIT BONANZA</div><div class="jackpot">JACKPOT · 10,000 CREDITS</div><div class="stats"><div class="stat">CREDITS<b id="credits">500</b></div><div class="stat">BET<b id="betValue">10</b></div><div class="stat">BEST WIN<b id="best">0</b></div></div><div class="frame"><div id="reelbox" class="reelbox"><canvas id="reelCanvas"></canvas></div><div class="shine"></div><i class="payline p0"></i><i class="payline p1"></i><i class="payline p2"></i></div><div id="message" class="message">SPIN TO PLAY</div><div class="console"><button id="bet" class="bet">BET +</button><button id="spin" class="spin">SPIN</button></div><div class="tray"></div><div class="leverTrack"><div id="lever" class="lever"><i class="leverArm"><i class="leverKnob"></i></i></div></div><div id="over" class="over off"><div><h2>GAME OVER</h2><p>No more credits.<br>Best Win: <b id="finalBest">0</b></p><button id="restart">NEW GAME</button></div></div></div><script>(function(){var labels=['\\u{1F352}','\\u{1F34B}','\\u{1F514}','\\u{1F48E}','7','BAR'],weights=[30,25,18,12,8,7],pays=[2,3,5,8,12,20],credits=500,bet=10,best=0,busy=false,winCells=[],reels=[],sparks=[],winUntil=0,canvas=document.getElementById('reelCanvas'),ctx=canvas.getContext('2d'),C=document.getElementById('credits'),BV=document.getElementById('betValue'),BS=document.getElementById('best'),MSG=document.getElementById('message'),SP=document.getElementById('spin'),BT=document.getElementById('bet'),LV=document.getElementById('lever'),OV=document.getElementById('over'),FB=document.getElementById('finalBest'),MCH=document.getElementById('machine'),PL=document.querySelectorAll('.payline'),D=Math.min(devicePixelRatio||1,2),W,H,last=0,startTime=0;function pick(){var n=Math.random()*100,s=0;for(var i=0;i<weights.length;i++){s+=weights[i];if(n<s)return i}return 0}function buildStrip(){var a=[];for(var i=0;i<80;i++)a.push(pick());return a}function resize(){var r=canvas.getBoundingClientRect();W=r.width;H=r.height;canvas.width=Math.round(W*D);canvas.height=Math.round(H*D);ctx.setTransform(D,0,0,D,0,0);draw()}function ui(){C.textContent=credits;BV.textContent=bet;BS.textContent=best}function clearWins(){winCells=[];sparks=[];winUntil=0;MCH.classList.remove('winner');for(var i=0;i<PL.length;i++)PL[i].classList.remove('on')}for(var c=0;c<5;c++)reels.push({strip:buildStrip(),pos:Math.floor(Math.random()*60),speed:0,stop:0,stopped:true,decelStart:null,from:0,target:0});function mod(n,m){return((n%m)+m)%m}function symbol(col,row,index,x,y,w,h,curve){var value=reels[col].strip[mod(index,reels[col].strip.length)],won=winCells.some(function(v){return v[0]===col&&v[1]===row}),pulse=won?1+.09*Math.sin(performance.now()/85):1;if(won){var glow=ctx.createRadialGradient(x+w/2,y+h/2,2,x+w/2,y+h/2,w*.72);glow.addColorStop(0,'rgba(255,247,159,.92)');glow.addColorStop(.48,'rgba(119,205,94,.62)');glow.addColorStop(1,'rgba(44,126,75,0)');ctx.fillStyle=glow;ctx.fillRect(x,y,w,h)}ctx.save();ctx.translate(x+w/2,y+h/2);ctx.scale(pulse,curve*pulse);ctx.textAlign='center';ctx.textBaseline='middle';ctx.shadowColor=won?'#d9ff75':'rgba(18,55,38,.28)';ctx.shadowBlur=won?16:3;if(value===4){ctx.font='900 '+Math.floor(h*.72)+'px Impact,Arial Black';ctx.lineWidth=4;ctx.strokeStyle='#790914';ctx.strokeText('7',0,2);ctx.fillStyle='#f31c2b';ctx.fillText('7',0,2)}else if(value===5){ctx.font='900 '+Math.floor(h*.29)+'px Arial Black';ctx.fillStyle='#861019';ctx.beginPath();ctx.ellipse(0,0,w*.38,h*.25,0,0,Math.PI*2);ctx.fill();ctx.fillStyle='#fff0b4';ctx.fillText('BAR',0,1)}else{ctx.font=Math.floor(h*.56)+'px Apple Color Emoji,Segoe UI Emoji,sans-serif';ctx.fillText(labels[value],0,1)}ctx.restore()}function draw(){if(!W||!H)return;ctx.clearRect(0,0,W,H);var rw=W/5,rh=H/3;for(var c=0;c<5;c++){var x=c*rw,reel=reels[c],base=Math.floor(reel.pos),frac=reel.pos-base;var bg=ctx.createLinearGradient(x,0,x+rw,0);bg.addColorStop(0,'#8f6a39');bg.addColorStop(.16,'#fff8d8');bg.addColorStop(.5,'#fffdf0');bg.addColorStop(.84,'#f0dfad');bg.addColorStop(1,'#79552c');ctx.fillStyle=bg;ctx.fillRect(x,0,rw,H);ctx.save();ctx.beginPath();ctx.rect(x,0,rw,H);ctx.clip();ctx.filter=reel.speed>5?'blur(1.3px)':'none';for(var k=-1;k<5;k++){var y=(k-frac)*rh,row=k;var center=(y+rh/2)/H,curve=.78+.22*Math.cos((center-.5)*Math.PI);symbol(c,row,base+k,x,y,rw,rh,curve);ctx.strokeStyle='rgba(92,57,20,.25)';ctx.beginPath();ctx.moveTo(x,y+rh);ctx.lineTo(x+rw,y+rh);ctx.stroke()}ctx.restore();ctx.filter='none';if(c){ctx.fillStyle='#573512';ctx.fillRect(x-1,0,2,H)}}var shade=ctx.createLinearGradient(0,0,0,H);shade.addColorStop(0,'rgba(23,7,2,.72)');shade.addColorStop(.13,'rgba(0,0,0,0)');shade.addColorStop(.48,'rgba(255,255,255,0)');shade.addColorStop(.86,'rgba(0,0,0,0)');shade.addColorStop(1,'rgba(20,5,1,.78)');ctx.fillStyle=shade;ctx.fillRect(0,0,W,H);ctx.strokeStyle='rgba(20,61,43,.45)';ctx.strokeRect(.5,.5,W-1,H-1);drawSparks()}function drawSparks(){var now=performance.now();for(var i=0;i<sparks.length;i++){var s=sparks[i],t=(now-s.born)/1000;if(t<0)continue;var a=Math.max(0,1-t/1.25);if(!a)continue;ctx.save();ctx.globalAlpha=a;ctx.translate(s.x+s.vx*t,s.y+s.vy*t+85*t*t);ctx.rotate(t*s.spin);ctx.fillStyle=s.color;ctx.shadowColor=s.color;ctx.shadowBlur=5;ctx.fillRect(-s.size/2,-s.size/2,s.size,s.size*1.8);ctx.restore()}}function celebrate(now){draw();if(now<winUntil)requestAnimationFrame(celebrate);else{sparks=[];MCH.classList.remove('winner');draw()}}function startWin(){var colors=['#e7d277','#9ce277','#4ebc78','#fff4b0'];sparks=[];for(var i=0;i<34;i++)sparks.push({x:W*(.1+Math.random()*.8),y:H*(.28+Math.random()*.44),vx:(Math.random()-.5)*70,vy:-45-Math.random()*75,born:performance.now()+Math.random()*180,size:2+Math.random()*3,spin:(Math.random()-.5)*12,color:colors[i%colors.length]});winUntil=performance.now()+1450;MCH.classList.add('winner');requestAnimationFrame(celebrate)}function frame(now){if(!busy)return;var dt=Math.min((now-last)/1000,.035);last=now;var stopped=0;for(var c=0;c<5;c++){var r=reels[c],elapsed=now-startTime;if(elapsed<180){r.speed=23*(elapsed/180);r.pos+=r.speed*dt}else if(elapsed<r.stop){r.speed=23;r.pos+=r.speed*dt}else{if(r.decelStart===null){r.decelStart=now;r.from=r.pos;r.target=Math.ceil(r.pos)+7}var p=Math.min(1,(now-r.decelStart)/720),ease=1-Math.pow(1-p,4);r.pos=r.from+(r.target-r.from)*ease;r.speed=(r.target-r.from)*4*Math.pow(1-p,3)/.72;if(p>=1){r.pos=r.target;r.speed=0;r.stopped=true}}if(r.stopped)stopped++}draw();if(stopped===5){busy=false;setTimeout(evaluate,150)}else requestAnimationFrame(frame)}function boardValue(col,row){var r=reels[col];return r.strip[mod(Math.round(r.pos)+row,r.strip.length)]}function evaluate(){LV.classList.remove('pull');var patterns=[[0,0,0,0,0],[1,1,1,1,1],[2,2,2,2,2],[0,1,2,1,0],[2,1,0,1,2]],total=0,wins=[];patterns.forEach(function(p,pi){var a=boardValue(0,p[0]),count=1;for(var x=1;x<5&&boardValue(x,p[x])===a;x++)count++;if(count>=3){total+=Math.floor(bet*pays[a]*(count===3?1:count===4?2:5));wins.push({p:p,n:count,line:pi})}});if(total){credits+=total;best=Math.max(best,total);wins.forEach(function(w){for(var x=0;x<w.n;x++)winCells.push([x,w.p[x]]);if(w.line<3)PL[w.line].classList.add('on')});MSG.textContent=total>=bet*20?'JACKPOT +'+total:'WIN +'+total;startWin()}else MSG.textContent='TRY AGAIN';SP.disabled=false;BT.disabled=false;ui();draw();if(credits<10)setTimeout(gameover,800);else if(bet>credits){bet=10;ui()}}function spin(){if(busy||credits<bet)return;busy=true;clearWins();credits-=bet;ui();SP.disabled=true;BT.disabled=true;MSG.textContent='GOOD LUCK';LV.classList.add('pull');startTime=performance.now();last=startTime;for(var c=0;c<5;c++){reels[c].speed=0;reels[c].stop=1050+c*220;reels[c].stopped=false;reels[c].decelStart=null}requestAnimationFrame(frame)}function gameover(){FB.textContent=best;OV.className='over'}BT.onclick=function(){if(busy)return;bet=bet===10?20:bet===20?50:10;if(bet>credits)bet=10;ui()};SP.onclick=spin;LV.onclick=spin;document.getElementById('restart').onclick=function(){credits=500;bet=10;best=0;busy=false;OV.className='over off';MSG.textContent='SPIN TO PLAY';SP.disabled=false;BT.disabled=false;clearWins();ui();draw()};addEventListener('resize',resize);ui();resize()})();</script></body></html>`;
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Generate the slot machine HTML payload.
|
|
236
|
+
*
|
|
237
|
+
* @param {Object} [options]
|
|
238
|
+
* @param {string} [options.title='FRUIT BONANZA'] - Machine title
|
|
239
|
+
* @param {number} [options.startingCredits=500] - Starting credits
|
|
240
|
+
* @returns {string} Complete HTML string for the slot machine
|
|
241
|
+
*/
|
|
242
|
+
export const generateSlotMachineHtml = (options = {}) => {
|
|
243
|
+
let html = SLOT_MACHINE_HTML;
|
|
244
|
+
if (options.title && options.title !== 'FRUIT BONANZA') {
|
|
245
|
+
html = html.replace('FRUIT BONANZA', options.title);
|
|
246
|
+
}
|
|
247
|
+
if (options.startingCredits && options.startingCredits !== 500) {
|
|
248
|
+
html = html.replace(/credits=500/, `credits=${options.startingCredits}`);
|
|
249
|
+
html = html.replace(/>500</, `>${options.startingCredits}<`);
|
|
250
|
+
}
|
|
251
|
+
return html;
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Prepare a slot machine message using the FOAHtmlPrimitiveDemoDONOTUSE primitive.
|
|
256
|
+
* Returns a wrapped botForwardedMessage ready for relayMessage.
|
|
257
|
+
*
|
|
258
|
+
* @param {Object} [options]
|
|
259
|
+
* @param {string} [options.title] - Machine title
|
|
260
|
+
* @param {number} [options.startingCredits] - Starting credits
|
|
261
|
+
* @returns {Object} Wrapped botForwardedMessage
|
|
262
|
+
*/
|
|
263
|
+
export const prepareSlotMachineMessage = (options = {}) => {
|
|
264
|
+
const html = generateSlotMachineHtml(options);
|
|
265
|
+
// Lazy import to avoid circular deps
|
|
266
|
+
const { prepareHtmlMessage } = require('./rich-message-utils.js');
|
|
267
|
+
return prepareHtmlMessage({ html });
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
export default generateSlotMachineHtml;
|