rampkit-expo-dev 0.0.29 → 0.0.30

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.
@@ -2,7 +2,7 @@ import { RampKitContext } from "./types";
2
2
  export declare const injectedHardening = "\n(function(){\n try {\n var meta = document.querySelector('meta[name=\"viewport\"]');\n if (!meta) { meta = document.createElement('meta'); meta.name = 'viewport'; document.head.appendChild(meta); }\n meta.setAttribute('content','width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover');\n var style = document.createElement('style');\n style.textContent='html,body{overflow-x:hidden!important;} html,body,*{-webkit-user-select:none!important;user-select:none!important;-webkit-touch-callout:none!important;-ms-user-select:none!important;touch-action: pan-y;} *{-webkit-tap-highlight-color: rgba(0,0,0,0)!important;} ::selection{background: transparent!important;} ::-moz-selection{background: transparent!important;} a,img{-webkit-user-drag:none!important;user-drag:none!important;-webkit-touch-callout:none!important} input,textarea{caret-color:transparent!important;-webkit-user-select:none!important;user-select:none!important}';\n document.head.appendChild(style);\n var prevent=function(e){e.preventDefault&&e.preventDefault();};\n document.addEventListener('gesturestart',prevent,{passive:false});\n document.addEventListener('gesturechange',prevent,{passive:false});\n document.addEventListener('gestureend',prevent,{passive:false});\n document.addEventListener('dblclick',prevent,{passive:false});\n document.addEventListener('wheel',function(e){ if(e.ctrlKey) e.preventDefault(); },{passive:false});\n document.addEventListener('touchmove',function(e){ if(e.scale && e.scale !== 1) e.preventDefault(); },{passive:false});\n document.addEventListener('selectstart',prevent,{passive:false,capture:true});\n document.addEventListener('contextmenu',prevent,{passive:false,capture:true});\n document.addEventListener('copy',prevent,{passive:false,capture:true});\n document.addEventListener('cut',prevent,{passive:false,capture:true});\n document.addEventListener('paste',prevent,{passive:false,capture:true});\n document.addEventListener('dragstart',prevent,{passive:false,capture:true});\n // Belt-and-suspenders: aggressively clear any attempted selection\n var clearSel=function(){\n try{var sel=window.getSelection&&window.getSelection(); if(sel&&sel.removeAllRanges) sel.removeAllRanges();}catch(_){} }\n document.addEventListener('selectionchange',clearSel,{passive:true,capture:true});\n document.onselectstart=function(){ clearSel(); return false; };\n try{ document.documentElement.style.webkitUserSelect='none'; document.documentElement.style.userSelect='none'; }catch(_){ }\n try{ document.body.style.webkitUserSelect='none'; document.body.style.userSelect='none'; }catch(_){ }\n var __selTimer = setInterval(clearSel, 160);\n window.addEventListener('pagehide',function(){ try{ clearInterval(__selTimer); }catch(_){} });\n // Continuously enforce no-select on all elements and new nodes\n var enforceNoSelect = function(el){\n try{\n el.style && (el.style.webkitUserSelect='none', el.style.userSelect='none', el.style.webkitTouchCallout='none');\n el.setAttribute && (el.setAttribute('unselectable','on'), el.setAttribute('contenteditable','false'));\n }catch(_){}\n }\n try{\n var all=document.getElementsByTagName('*');\n for(var i=0;i<all.length;i++){ enforceNoSelect(all[i]); }\n var obs = new MutationObserver(function(muts){\n for(var j=0;j<muts.length;j++){\n var m=muts[j];\n if(m.type==='childList'){\n m.addedNodes && m.addedNodes.forEach && m.addedNodes.forEach(function(n){ if(n && n.nodeType===1){ enforceNoSelect(n); var q=n.getElementsByTagName? n.getElementsByTagName('*'): []; for(var k=0;k<q.length;k++){ enforceNoSelect(q[k]); }}});\n } else if(m.type==='attributes'){\n enforceNoSelect(m.target);\n }\n }\n });\n obs.observe(document.documentElement,{ childList:true, subtree:true, attributes:true, attributeFilter:['contenteditable','style'] });\n }catch(_){ }\n } catch(_) {}\n})(); true;\n";
3
3
  export declare const injectedNoSelect = "\n(function(){\n try {\n if (window.__rkNoSelectApplied) return true;\n window.__rkNoSelectApplied = true;\n var style = document.getElementById('rk-no-select-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'rk-no-select-style';\n style.innerHTML = \"\n * {\n user-select: none !important;\n -webkit-user-select: none !important;\n -webkit-touch-callout: none !important;\n }\n ::selection {\n background: transparent !important;\n }\n \";\n document.head.appendChild(style);\n }\n var prevent = function(e){ if(e && e.preventDefault) e.preventDefault(); return false; };\n document.addEventListener('contextmenu', prevent, { passive: false, capture: true });\n document.addEventListener('selectstart', prevent, { passive: false, capture: true });\n } catch (_) {}\n true;\n})();\n";
4
4
  export declare const injectedVarsHandler = "\n(function(){\n try {\n if (window.__rkVarsHandlerApplied) return true;\n window.__rkVarsHandlerApplied = true;\n \n // Handler function that updates variables and notifies the page\n window.__rkHandleVarsUpdate = function(vars) {\n if (!vars || typeof vars !== 'object') return;\n // Update the global variables object\n window.__rampkitVariables = vars;\n // Dispatch a custom event that the page's JS can listen to for re-rendering\n try {\n document.dispatchEvent(new CustomEvent('rampkit:vars-updated', { detail: vars }));\n } catch(e) {}\n // Also try calling a global handler if the page defined one\n try {\n if (typeof window.onRampkitVarsUpdate === 'function') {\n window.onRampkitVarsUpdate(vars);\n }\n } catch(e) {}\n };\n \n // Listen for message events from React Native\n document.addEventListener('message', function(event) {\n try {\n var data = event.data;\n if (data && data.type === 'rampkit:variables' && data.vars) {\n window.__rkHandleVarsUpdate(data.vars);\n }\n } catch(e) {}\n }, false);\n \n // Also listen on window for compatibility\n window.addEventListener('message', function(event) {\n try {\n var data = event.data;\n if (data && data.type === 'rampkit:variables' && data.vars) {\n window.__rkHandleVarsUpdate(data.vars);\n }\n } catch(e) {}\n }, false);\n } catch (_) {}\n true;\n})();\n";
5
- export declare const injectedTemplateResolver = "\n(function(){\n try {\n if (window.__rkTemplateResolverApplied) return true;\n window.__rkTemplateResolverApplied = true;\n \n // Template pattern: matches ${varName}\n var TEMPLATE_MARKER = '$' + '{';\n var TEMPLATE_REGEX = /\\x24\\x7B([A-Za-z_][A-Za-z0-9_.]*)\\x7D/g;\n \n // Build variable map from context\n function buildVarMap() {\n var vars = {};\n var ctx = window.rampkitContext || { device: {}, user: {} };\n var state = window.__rampkitVariables || {};\n \n // Device vars (device.xxx)\n if (ctx.device) {\n Object.keys(ctx.device).forEach(function(key) {\n vars['device.' + key] = ctx.device[key];\n });\n }\n \n // User vars (user.xxx)\n if (ctx.user) {\n Object.keys(ctx.user).forEach(function(key) {\n vars['user.' + key] = ctx.user[key];\n });\n }\n \n // State vars (varName - no prefix)\n Object.keys(state).forEach(function(key) {\n vars[key] = state[key];\n });\n \n return vars;\n }\n \n // Format a value for display\n function formatValue(value) {\n if (value === undefined || value === null) return '';\n if (typeof value === 'boolean') return value ? 'true' : 'false';\n if (typeof value === 'object') return JSON.stringify(value);\n return String(value);\n }\n \n // Resolve templates in a single text node\n function resolveTextNode(node, vars) {\n var text = node.textContent;\n if (!text || text.indexOf(TEMPLATE_MARKER) === -1) return;\n \n var resolved = text.replace(TEMPLATE_REGEX, function(match, varName) {\n if (vars.hasOwnProperty(varName)) {\n return formatValue(vars[varName]);\n }\n return match; // Keep original if var not found\n });\n \n if (resolved !== text) {\n node.textContent = resolved;\n }\n }\n \n // Resolve templates in all text nodes\n function resolveAllTemplates() {\n var vars = buildVarMap();\n var walker = document.createTreeWalker(\n document.body,\n NodeFilter.SHOW_TEXT,\n null,\n false\n );\n \n var node;\n while (node = walker.nextNode()) {\n resolveTextNode(node, vars);\n }\n \n // Also resolve in attribute values that might contain templates\n var allElements = document.body.getElementsByTagName('*');\n for (var i = 0; i < allElements.length; i++) {\n var el = allElements[i];\n for (var j = 0; j < el.attributes.length; j++) {\n var attr = el.attributes[j];\n if (attr.value && attr.value.indexOf(TEMPLATE_MARKER) !== -1) {\n var resolvedAttr = attr.value.replace(TEMPLATE_REGEX, function(match, varName) {\n if (vars.hasOwnProperty(varName)) {\n return formatValue(vars[varName]);\n }\n return match;\n });\n if (resolvedAttr !== attr.value) {\n el.setAttribute(attr.name, resolvedAttr);\n }\n }\n }\n }\n }\n \n // Run on DOMContentLoaded\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', resolveAllTemplates);\n } else {\n // DOM already ready, run immediately\n resolveAllTemplates();\n }\n \n // Also run after a short delay to catch dynamically added content\n setTimeout(resolveAllTemplates, 100);\n \n // Expose for manual re-resolution\n window.rampkitResolveTemplates = resolveAllTemplates;\n \n // Re-resolve when variables update\n document.addEventListener('rampkit:vars-updated', function() {\n setTimeout(resolveAllTemplates, 0);\n });\n \n } catch(e) {\n console.log('[Rampkit] Template resolver error:', e);\n }\n true;\n})();\n";
5
+ export declare const injectedTemplateResolver: string;
6
6
  export type ScreenPayload = {
7
7
  id: string;
8
8
  html: string;
@@ -174,131 +174,83 @@ exports.injectedVarsHandler = `
174
174
  })();
175
175
  `;
176
176
  // Template resolution script that replaces ${device.xxx} and ${user.xxx} with actual values
177
- // This runs on DOMContentLoaded and can be re-triggered via window.rampkitResolveTemplates()
178
- exports.injectedTemplateResolver = `
179
- (function(){
180
- try {
181
- if (window.__rkTemplateResolverApplied) return true;
182
- window.__rkTemplateResolverApplied = true;
183
-
184
- // Template pattern: matches ${'$'}{varName}
185
- var TEMPLATE_MARKER = '$' + '{';
186
- var TEMPLATE_REGEX = /\\x24\\x7B([A-Za-z_][A-Za-z0-9_.]*)\\x7D/g;
187
-
188
- // Build variable map from context
189
- function buildVarMap() {
190
- var vars = {};
191
- var ctx = window.rampkitContext || { device: {}, user: {} };
192
- var state = window.__rampkitVariables || {};
193
-
194
- // Device vars (device.xxx)
195
- if (ctx.device) {
196
- Object.keys(ctx.device).forEach(function(key) {
197
- vars['device.' + key] = ctx.device[key];
198
- });
199
- }
200
-
201
- // User vars (user.xxx)
202
- if (ctx.user) {
203
- Object.keys(ctx.user).forEach(function(key) {
204
- vars['user.' + key] = ctx.user[key];
205
- });
206
- }
207
-
208
- // State vars (varName - no prefix)
209
- Object.keys(state).forEach(function(key) {
210
- vars[key] = state[key];
211
- });
212
-
213
- return vars;
214
- }
215
-
216
- // Format a value for display
217
- function formatValue(value) {
218
- if (value === undefined || value === null) return '';
219
- if (typeof value === 'boolean') return value ? 'true' : 'false';
220
- if (typeof value === 'object') return JSON.stringify(value);
221
- return String(value);
222
- }
223
-
224
- // Resolve templates in a single text node
225
- function resolveTextNode(node, vars) {
226
- var text = node.textContent;
227
- if (!text || text.indexOf(TEMPLATE_MARKER) === -1) return;
228
-
229
- var resolved = text.replace(TEMPLATE_REGEX, function(match, varName) {
230
- if (vars.hasOwnProperty(varName)) {
231
- return formatValue(vars[varName]);
232
- }
233
- return match; // Keep original if var not found
234
- });
235
-
236
- if (resolved !== text) {
237
- node.textContent = resolved;
238
- }
239
- }
240
-
241
- // Resolve templates in all text nodes
242
- function resolveAllTemplates() {
243
- var vars = buildVarMap();
244
- var walker = document.createTreeWalker(
245
- document.body,
246
- NodeFilter.SHOW_TEXT,
247
- null,
248
- false
249
- );
250
-
251
- var node;
252
- while (node = walker.nextNode()) {
253
- resolveTextNode(node, vars);
254
- }
255
-
256
- // Also resolve in attribute values that might contain templates
257
- var allElements = document.body.getElementsByTagName('*');
258
- for (var i = 0; i < allElements.length; i++) {
259
- var el = allElements[i];
260
- for (var j = 0; j < el.attributes.length; j++) {
261
- var attr = el.attributes[j];
262
- if (attr.value && attr.value.indexOf(TEMPLATE_MARKER) !== -1) {
263
- var resolvedAttr = attr.value.replace(TEMPLATE_REGEX, function(match, varName) {
264
- if (vars.hasOwnProperty(varName)) {
265
- return formatValue(vars[varName]);
266
- }
267
- return match;
268
- });
269
- if (resolvedAttr !== attr.value) {
270
- el.setAttribute(attr.name, resolvedAttr);
271
- }
272
- }
273
- }
274
- }
275
- }
276
-
277
- // Run on DOMContentLoaded
278
- if (document.readyState === 'loading') {
279
- document.addEventListener('DOMContentLoaded', resolveAllTemplates);
280
- } else {
281
- // DOM already ready, run immediately
282
- resolveAllTemplates();
283
- }
284
-
285
- // Also run after a short delay to catch dynamically added content
286
- setTimeout(resolveAllTemplates, 100);
287
-
288
- // Expose for manual re-resolution
289
- window.rampkitResolveTemplates = resolveAllTemplates;
290
-
291
- // Re-resolve when variables update
292
- document.addEventListener('rampkit:vars-updated', function() {
293
- setTimeout(resolveAllTemplates, 0);
294
- });
295
-
296
- } catch(e) {
297
- console.log('[Rampkit] Template resolver error:', e);
298
- }
299
- true;
300
- })();
301
- `;
177
+ // Built using string concatenation to avoid template literal escaping issues
178
+ exports.injectedTemplateResolver = [
179
+ "(function(){",
180
+ " try {",
181
+ " if (window.__rkTemplateResolverApplied) return true;",
182
+ " window.__rkTemplateResolverApplied = true;",
183
+ " ",
184
+ " console.log('[Rampkit] Template resolver starting...');",
185
+ " console.log('[Rampkit] rampkitContext:', JSON.stringify(window.rampkitContext));",
186
+ " ",
187
+ " function buildVarMap() {",
188
+ " var vars = {};",
189
+ " var ctx = window.rampkitContext || { device: {}, user: {} };",
190
+ " var state = window.__rampkitVariables || {};",
191
+ " if (ctx.device) {",
192
+ " Object.keys(ctx.device).forEach(function(key) {",
193
+ " vars['device.' + key] = ctx.device[key];",
194
+ " });",
195
+ " }",
196
+ " if (ctx.user) {",
197
+ " Object.keys(ctx.user).forEach(function(key) {",
198
+ " vars['user.' + key] = ctx.user[key];",
199
+ " });",
200
+ " }",
201
+ " Object.keys(state).forEach(function(key) {",
202
+ " vars[key] = state[key];",
203
+ " });",
204
+ " console.log('[Rampkit] Variable map:', JSON.stringify(vars));",
205
+ " return vars;",
206
+ " }",
207
+ " ",
208
+ " function formatValue(value) {",
209
+ " if (value === undefined || value === null) return '';",
210
+ " if (typeof value === 'boolean') return value ? 'true' : 'false';",
211
+ " if (typeof value === 'object') return JSON.stringify(value);",
212
+ " return String(value);",
213
+ " }",
214
+ " ",
215
+ " function resolveAllTemplates() {",
216
+ " console.log('[Rampkit] Resolving templates...');",
217
+ " var vars = buildVarMap();",
218
+ " var pattern = /\\$\\{([A-Za-z_][A-Za-z0-9_.]*)\\}/g;",
219
+ " var bodyHtml = document.body.innerHTML;",
220
+ " var marker = String.fromCharCode(36, 123);", // $ = 36, { = 123
221
+ " var hasTemplates = bodyHtml.indexOf(marker) !== -1;",
222
+ " console.log('[Rampkit] Body has templates:', hasTemplates);",
223
+ " if (hasTemplates) {",
224
+ " var newHtml = bodyHtml.replace(pattern, function(match, varName) {",
225
+ " console.log('[Rampkit] Found template:', match, 'varName:', varName);",
226
+ " if (vars.hasOwnProperty(varName)) {",
227
+ " var value = formatValue(vars[varName]);",
228
+ " console.log('[Rampkit] Replacing with:', value);",
229
+ " return value;",
230
+ " }",
231
+ " console.log('[Rampkit] No value found for:', varName);",
232
+ " return match;",
233
+ " });",
234
+ " if (newHtml !== bodyHtml) {",
235
+ " document.body.innerHTML = newHtml;",
236
+ " console.log('[Rampkit] Templates resolved!');",
237
+ " }",
238
+ " }",
239
+ " }",
240
+ " ",
241
+ " setTimeout(resolveAllTemplates, 50);",
242
+ " setTimeout(resolveAllTemplates, 200);",
243
+ " window.rampkitResolveTemplates = resolveAllTemplates;",
244
+ " document.addEventListener('rampkit:vars-updated', function() {",
245
+ " setTimeout(resolveAllTemplates, 0);",
246
+ " });",
247
+ " console.log('[Rampkit] Template resolver initialized');",
248
+ " } catch(e) {",
249
+ " console.log('[Rampkit] Template resolver error:', e);",
250
+ " }",
251
+ " true;",
252
+ "})();",
253
+ ].join("\n");
302
254
  function performRampkitHaptic(event) {
303
255
  if (!event || event.action !== "haptic") {
304
256
  // Backwards compatible default
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rampkit-expo-dev",
3
- "version": "0.0.29",
3
+ "version": "0.0.30",
4
4
  "description": "The Expo SDK for RampKit. Build, test, and personalize app onboardings with instant updates.",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",